Is there before_filter in django as in rails?

老子叫甜甜 提交于 2019-12-23 17:33:27

问题


Is there any feature available in django so that we can combine some filtering on all actions in the view of django, like before_filter: is available in rails.


回答1:


No. before_, around_ and after_ filter concepts aren't present in Django, but it isn't hard to write your own functions to do the same thing. There are also signals and generic views that might accomplish what you're needing to do.




回答2:


I'm still learning Rails but from what I've observed so far python decorators also seem to be used in Django in a very similar way to the before_filter in Rails.

Here's one example of it's usage in authenticating users: https://docs.djangoproject.com/en/1.2/topics/auth/#the-login-required-decorator



来源:https://stackoverflow.com/questions/6584512/is-there-before-filter-in-django-as-in-rails

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