Why we need to write return wrapper in wrapper function?
and why add=login_required (add) we are writing can’t we just call login_required(add)
Why we are returning wrapper in wrapper function
Hello @i.m.anand_31, pls, understand this concept carefully. There are some instances where we want to authenticate our user and on that basis, we want to redirect it to some other page and want to show something else.
So for this, we can use the decorators and create our own functions like login_required(func)
So this login_required is a function that is returning function on validating the username and password else returning the not authenticated.
So if you see carefully login_required is returning the wrapper function and not the wrapper function to itself.
So this means if everything is fine then pass the *args and **kwargs to the function that we passed and now we can execute them properly.
And add = login_required(add)
This means we defined the function def add(a,b): and now we are assigning this value to the add that is just validating if everything is fine or not.
I know this is little bit confusing but this will take time. You will get full understanding of this as you progress further on.
Incase of any confusion pls feel free to reach me out. Incase it is clear to you pls mark it as resolve.
Thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.