Django permission

Category: /knowledge /django
Tags: django

Template

display logged in user name

  {% if user.is_authenticated %}
    {{ user.username }} <a href=".">Logout</a>
  {% else %}
    <a href="."> Login </a>
  {% endif %}

check if has permission on some tables

Display a link based on user permission to ‘song’ table, in app ‘hymn’.

{% if perms.hymn %}
  <a href="{% url admin:hymn_song_change song.pk %}"> Edit this song </a>
{% endif %}

讨论

提示

  • 如果看不到讨论部分, 请暂时关掉adblock in Firefox/Chrome
  • 本网站使用Javascript实现评论功能, 此处外链对提高您的网站PR没有帮助. (潜台词: 请不要灌水, 谢谢)