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

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -