Possible Duplicate:
Understanding Python decorators
What does a Python decorator do? And where can I see the codes that are running when I add a decorator to a method?
For example, when I add @login_required at the top of a method, does any code replace that line? How exactly does this line check the user session?
Kind of. Adding
@login_requiredbefore your view function has the same effect as doing this:For explanations of decorators in Python, see:
So decorator functions accept an original function, and return a function that (probably) calls the original function, but does something else too.
In the case of
login_required, I think it checks the request object passed to view functions to see if the user is authenticated.