Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can custom Django filters access request.user?

Is it possible to access the current User (i.e. user in the template context) from a custom template filter?

Obviously I can pass the user in as an argument, but if it's possible to just grab the current user, that would be more convenient.

like image 996
dcrosta Avatar asked Jul 13 '11 18:07

dcrosta


1 Answers

Django filters aren't given any special access to the context from which they are called, they're just plain old functions.

You'll need to pass in anything you want to use within the function.

https://docs.djangoproject.com/en/dev/howto/custom-template-tags/

like image 105
Chris W. Avatar answered Nov 08 '22 14:11

Chris W.