I'm having a small issue with my permissions in my Django template.
I'm trying to, based on permissions, show an icon in the menu bar for my project. I want to have it so that if the user has the permissions to add a new follow-up to the project, they can see the icon, if they don't have that permission, then do not display the link.
My permission syntax is follow.add_followup
, which I got from printing user.get_all_permissions()
.
I have 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 display the template, I am presented with this error:
TemplateSyntaxError at /project/232/view/
Could not parse the remainder: '(followup.add_followup)' from 'user.has_perm(followup.add_followup)'
Any thoughts? This has been giving me a headache! :)
This kind of complex decision-making goes in the view functions.
Or it goes into the context which is then presented to the template.
https://stackoverflow.com/search?q=%5Bdjango%5D+context
When to use context processor
Do this in your view
Then your template is simply