Get Django User group in HTML -


i trying django user's group in html if tag. tried:

{% ifequal user.groups.all.0 'abc' %} {% endif %} 

but not working. other way there?

try this:

{% group in request.user.groups.all %}     {% if group.name == 'abc' %}{% endif %} {% endfor %} 

or

{% if request.user.groups.all.0.name == 'abc' %}{% endif %} 

you have access current user object request context variable. this, make sure django.template.context_processors.request in template settings.

request.user.groups.all.0 returns group model object, have compare against name field.


Comments

Popular posts from this blog

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -