Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there before_filter in django as in rails?

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.

like image 907
Nazar Hussain Avatar asked Oct 15 '25 14:10

Nazar Hussain


2 Answers

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

like image 181
Ariel Avatar answered Oct 18 '25 13:10

Ariel


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.

like image 33
Brandon Avatar answered Oct 18 '25 14:10

Brandon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!