Check Model Permissions within Templates in Django

2023-08-08 20:52 (1 years ago) ytyng

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 %}
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011