问题
Suppose I have 20 views inside views.py
How do I set a decorator on top of each function? Without manually pasting one on top?
回答1:
I found a discussion regarding this here: http://groups.google.com/group/django-users/browse_thread/thread/2cff3374d365998d/24cd8b86b73d3832?lnk=raot&pli=1
The general conclusion is that you could write some code to auto-apply your decorator to all views, but that in general it is not worth the trouble and later confusion.
回答2:
You can decorate all your views in urls.py: http://djangosnippets.org/snippets/532/ .
来源:https://stackoverflow.com/questions/4505499/how-do-i-set-a-decorator-for-every-one-of-my-django-views