[英]Django Jinja How to check whether the user has any rights through the template?
I have a menu whose parts are displayed depending on the rights.我有一个菜单,其部分根据权限显示。 I configured it.
我配置了它。 I want to check if the user has any rights in principle, if they do not, then the menu will not reach the moment of drawing.
我想检查用户原则上是否有任何权限,如果没有,则菜单不会到达绘制的那一刻。 Something like this:
像这样的东西:
{% if perms.registration2 == NUll %}
# render something
{% endif %}
This code returns set()
not NULL
or ''
:此代码返回
set()
而不是NULL
或''
:
{{ perms.registration2 }}
How can I do such a check?我怎样才能做这样的检查?
You can check permission in your template like this:您可以像这样检查模板中的权限:
{% if perms.app_label.permission_name %}
# do something
{% endif %}
If your trying to check whether the current user has any permission or not you can try this:如果您尝试检查当前用户是否有任何权限,您可以尝试以下操作:
{% if not request.user.permissions.all %}
# do something
{% endif %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.