django - Load HTML if User belongs to a certain group -


i want show link if user belongs group.

html:

{% if user.is_authenticated %}     {% users_in_group = group.objects.get(name="boss").user_set.all() %}     {% if user in users_in_group %}     <li><a href='/register'>create user</a></li>     {% endif %} {% endif %} 

very thanks

to solve did following

view:

if request.user.is_authenticated():     = request.user.groups.count()     if > 0:         #a = request.user.groups.all()[0] #trae el nombre del grupo          = "jefe"     else:         = "no user groups"     else:     = "user not log" 

base.html:

  {% if user.is_authenticated %}     {% if in "jefes" %}       <li><a href='/usuarios'>usuarios</a></li>     {% endif %}      {% endif %} 

i not know if it's best served.


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -