可以自定义Django过滤器访问request.user吗? [英] Can custom Django filters access request.user?

查看:119
本文介绍了可以自定义Django过滤器访问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.

推荐答案

Django过滤器没有给他们调用的上下文的任何特殊访问权限,它们只是简单的旧功能。

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/

这篇关于可以自定义Django过滤器访问request.user吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆