Django在已安装的应用程序中没有明确的应用程序标签

时间:2019-02-13 21:18:49

标签: python django

我遇到运行时错误 Model类account.models.User未声明显式app_label,并且不在INSTALLED_APPS中的应用程序中。在花了数小时的时间在网上搜索解决方案后,我仍然无法弄清楚我在做什么错。 (注意:使用Django 1.11)

models.py

class User(AbstractBaseUser):
    email = models.EmailField(
        verbose_name='email address',
        max_length=255,
        unique=True,
    )
    active = models.BooleanField(default=True)
    staff = models.BooleanField(default=False) # a admin user; non super-user
    admin = models.BooleanField(default=False) # a superuser
    verified = models.BooleanField(default=False)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = [] # Email & Password are required by default.

    objects = UserManager()

    def get_full_name(self):
        # The user is identified by their email address
        return self.email

    def get_short_name(self):
        # The user is identified by their email address
        return self.email

    def __str__(self):              # __unicode__ on Python 2
        return self.email

    def has_perm(self, perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, app_label):
        "Does the user have permissions to view the app `app_label`?"
        # Simplest possible answer: Yes, always
        return True

    @property
    def is_staff(self):
        "Is the user a member of staff?"
        return self.staff

    @property
    def is_admin(self):
        "Is the user a admin member?"
        return self.admin

    @property
    def is_active(self):
        "Is the user active?"
        return self.active

    @property
    def is_verified(self):
        "Has the user verified their email?"
        return self.verified

    def email_user(self, subject, message, from_email=None, **kwargs):
        send_mail(subject, message, from_email, [self.email], **kwargs)

settings.py

AUTH_USER_MODEL = 'accounts.User'

...

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'accounts',
    'demoapp',
]

帐户/apps.py

from django.apps import AppConfig


class AccountsConfig(AppConfig):
    name = 'accounts'

1 个答案:

答案 0 :(得分:1)

在您的 str = 'aaaaa\bb'; console.log([...str]);类声明上,包括:

User