User Permissions for Django Module

I have a little problem with my permissions in my Django template.

I'm trying to show an icon in the menu bar for my project based on permissions. I want to have it so that if the user has permissions to add a new project to the project, he can see the icon, if he does not have this permission, and then not display the link.

The syntax of the syntax follow.add_followupI received from printing user.get_all_permissions().

I tried this code in my template:

...
{% if user.has_perm('followup.add_followup') %}
<li><a href="{% url followup-new p.id %}">Log</a></li>
{% endif %}
...

But when I show the template, this error seems to me:

TemplateSyntaxError at / project / 232 / view /

Failed to parse the remainder: '(followup.add_followup)' from 'user.has_perm (followup.add_followup)'

Any thoughts? It gave me a headache! :)

+3
4

:

.

, .

https://stackoverflow.com/search?q=%5Bdjango%5D+context

def my_view( request ):
    followup= user.has_perm('followup.add_followup')
    # etc.
    return render_to_response( template, {'followup':followup,... )

{% if followup %}
<li><a href="{% url followup-new p.id %}">Log</a></li>
{% endif %}
+1

Django, nextg...

{%if perms.followup.add_followup%}your URL here{%endif%}

EDIT: Django 3 : "", "" "". , Meta... :

somemodels.py

class SomeModel(Model):
    ...
    class Meta:
    permissions = (('add_followup','Can see add urls'),(...))

Django . Django,

<app_label>.<codename>

:

{%if perms.somemodels.add_followup%}your URL here{%endif%}

, , , ...

{{perms.somemodels}}

, somemodel - , .

+11

Django # 2: https://docs.djangoproject.com/en/dev/topics/auth/#id9

{{perms}}. django.contrib.auth.context_processors.PermWrapper, - .

+2

, :

:

.......

{% if 'user.can_drink' in user.get_all_permissions %}
   {{ user }} can drink.
   .......
{% else %}
   {{ user }} can´t drink.
    ........
{% endif %}

.......
+2

Source: https://habr.com/ru/post/1789800/


All Articles