定义用户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 %}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2021-08-14
  • 2021-07-16
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-29
  • 2021-07-06
  • 2021-06-10
相关资源
相似解决方案