gpt4 book ai didi

python - 查找错误 : No installed app with label 'user'

转载 作者:太空狗 更新时间:2023-10-30 02:58:59 24 4
gpt4 key购买 nike

我在运行以下代码时收到 LookupError: No installed app with label 'user':

from django.db import models

from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

class UserManager(BaseUserManager):

def _create_user(self, username, email, password, is_staff, is_superuser,
**extra_fields):

if not email:
raise ValueError('El email debe de ser obligatorio')

email = self.normalize_email(email)
user = self.model(username=username, email=email, is_activate=True,
is_staff=is_staff, is_superuser=is_superuser, **extra_fields)
user.set_password(password)
user.save(using = self.db)
return user

def create_user(self, username, email, password=None,
**extra_fields):
return self._create_user(username, email, password, False, False, **extra_fields)

def create_superuser(self, username, email, password,
**extra_fields):
return self._create_user(username, email, password, True, True, **extra_fields)

class User(AbstractBaseUser, PermissionsMixin):

username = models.CharField(max_length=50, unique=True)
email = models.EmailField(max_length=50, unique=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
avatar = models.URLField()


objects = UserManager()

is_activate = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)

USERNAME_FIELD = 'username'
REQUIRE_FIELDS = ['email']

def get_short_name(self):
return self.username

错误的来源不是很明显,为什么会出现这个错误?

特别是哪一行正在寻找“用户”标签,为什么找不到它要找的东西?

最佳答案

你需要在settings.py中设置AUTH_USER_MODEL为自定义用户模型

并且还将具有自定义用户模型的应用包含到 settings.py 中的 INSTALLED_APPS

关于python - 查找错误 : No installed app with label 'user' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32570526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com