django perm用法

定义用户model时可以给用户分配权限:

class Meta:
  permissions = (
       ("can_mark", "Can mark"),
              )

views里的判断:

if request.user.has_perm('accounts.can_mark'):

或者在模板里

{% if perms.accounts %}
  <p>You have permission to do something in the polls app.</p>
  {% if perms.accounts.can_vote %}
    <p>You can vote!</p>
  {% endif %}
{% else %}
  <p>You don't have permission to do anything in the polls app.</p>
{% endif %}

posted on 2014-07-21 19:32  颓废的悠然  阅读(965)  评论(1编辑  收藏  举报

导航