Django 익명 사용자 AnonymousUser
2708 단어 Djano
from django.contrib.auth.models import AnonymousUser
class AnonymousUser:
id = None
pk = None
username = ''
is_staff = False
is_active = False
is_superuser = False
_groups = EmptyManager(Group)
_user_permissions = EmptyManager(Permission)
def __str__(self):
return 'AnonymousUser'
def __eq__(self, other):
return isinstance(other, self.__class__)
def __hash__(self):
return 1 # instances always return the same hash value
def save(self):
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def delete(self):
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def set_password(self, raw_password):
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
def check_password(self, raw_password):
raise NotImplementedError("Django doesn't provide a DB representation for AnonymousUser.")
@property
def groups(self):
return self._groups
@property
def user_permissions(self):
return self._user_permissions
def get_group_permissions(self, obj=None):
return set()
def get_all_permissions(self, obj=None):
return _user_get_all_permissions(self, obj=obj)
def has_perm(self, perm, obj=None):
return _user_has_perm(self, perm, obj=obj)
def has_perms(self, perm_list, obj=None):
return all(self.has_perm(perm, obj) for perm in perm_list)
def has_module_perms(self, module):
return _user_has_module_perms(self, module)
@property
def is_anonymous(self):
return True
@property
def is_authenticated(self):
return False
def get_username(self):
return self.username
104591410 객체
AnonymousUser
class models.
¶ AnonymousUser
은 django.contrib.auth.models.AnonymousUser
의 인터페이스를 실현하는 유형으로 다음과 같은 차이가 있다.django.contrib.auth.models.User
입니다.None
은 항상 빈 문자열입니다.username
은 항상 빈 문자열을 반환합니다.get_username()
is_anonymous
True
False
is_authenticated
그리고 False
영원히 True
.is_staff
영원히 is_superuser
False
그리고 is_active
은 항상 비어 있습니다.False
, groups
, user_permissions
과 set_password()
이 check_password()
증가했다.