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
Post a Comment