How do I set a decorator for every one of my Django views?

▼魔方 西西 提交于 2020-01-06 05:43:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!