Check Model Permissions within Templates in Django
2023-08-08 11:52 (2 years ago)
Here is an example of determining whether a logged-in user has permissions for a model using Django's template language.
There is a default template variable called perms, which can be used to make this determination.
{% if perms.myapp.view_mymodel %}
<li class="nav-item">
<a href="{% url 'admin:myapp_mymodel_changelist' %}" class="nav-link">Admin Page</a>
</li>
{% endif %}
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.