为什么此代码仅对超级用户返回true

该代码在理论上应阻止未经提及的许可的用户。可能是一个缓存问题,因为我在github上找到了与此问题有关的帖子,但来自其他版本的django


from django.shortcuts import render
from django.http import HttpResponse
from .models import chem

# Create your views here.


def console(request):
    if request.user.has_perm('bio_lab.can_view_chem'):
        print('works')
        istekler = chem.objects.all()
        return render(request,'console.html',locals())
    else:
        print('error')
'''
jianglongdi 回答:为什么此代码仅对超级用户返回true

超级用户活动的任何用户都被假定具有所有权限-这是设计使然。

这是User.has_perm的源代码:

def has_perm(self,perm,obj=None):

    # Active superusers have all permissions.
    if self.is_active and self.is_superuser:
        return True

    # Otherwise we need to check the backends.
    return _user_has_perm(self,obj)
本文链接:https://www.f2er.com/3080362.html

大家都在问