Is there any difference in using login_required decorator in urls.py and in views.py ?
If I put this line:
url(r'^add/$', login_required(views.add_media), name = 'add_media_action')
into urls.py will I achieve the same effect as decorating add_media function in views.py:
@login_required
def add_media(request):
...
In Python, a decorator is a function that takes a function as an argument, and returns a decorated function. The
@login_requiredsyntax can be translated to:So if you apply the decorator manually (as in your first snippet), it should generate the same effect.
The approach in your first snippet is useful if you want to use both the decorated and undecorated versions of your view.