¿Cómo verificar si el usuario está en un grupo con soporte 'o algo más' en la plantilla de django?
Frecuentes
Visto 490 equipos
1
For now I used ifuseringroup tag but now I need to add exception for users with specific permission so I need something like this (pseudocode)
{% ifuseringroup 'masters' or perms.app_label.can_see_this %}
Anyone knows a group checking tag that will accept or
and then standard django if
tag expression?
Or can help me using other approach?
2 Respuestas
1
Yo iria con this template filter:
{% if user|in_group:'masters' or perms.app_label.can_see_this %}
...
{% endif %}
contestado el 22 de mayo de 14 a las 13:05
0
If you are looking to check for permissions in templates, the following code would suffice:
{% if perms.app_label.can_do_something %}
<form here>
{% endif %}
Where model refers to the model that the user need permissions to see the form for.
Consulte https://docs.djangoproject.com/en/1.6/topics/auth/default/#permissions para mas ejemplos
The currently logged-in user's permissions are stored in the template variable {{ perms }}
contestado el 22 de mayo de 14 a las 13:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas django tags django-templates or haz tu propia pregunta.
I know that . Im looking for the way to check if user is in group or <any else template if statement returns true> like: if user is in group biggroup or his name is marta. Or: if user is in group smallgroup or perms.appllabel.canseethis. if you got the idea how to better rephrase the question fell free to suggest that. - Señor_JABA
I'm already usig it but it's not supporting
or
statement. Or maybe I'm wrong - how would you use it to check if user is in group "superg" OR his first_name is "marta"? - Señor_JABA