django:LookupError:App'没有'模特'模型

时间:2016-07-29 18:22:27

标签: python django

enter image description here

我正在使用https://bixly.com/blog/awesome-forms-django-crispy-forms/,尝试使用django crispy表单设置bootstrap 3表单。

在app1 / models.py中,我已经设置了表单:

from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractUser
from django import forms


class User(AbstractUser):

    # Address
    contact_name = models.CharField(max_length=50)
    contact_address = models.CharField(max_length=50)
    contact_email = models.CharField(max_length=50)
    contact_phone = models.CharField(max_length=50)
    ......

请注意我还没有创建任何数据库表。在这个阶段我不需要它们。我只是想让表单正常工作。当我跑步时,我得到:

Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x02B63EF0>
Traceback (most recent call last):
  File "C:\lib\site-packages\django\utils\autoreload.py", line 222, in wrapper
    fn(*args, **kwargs)
  File "C:\lib\site-packages\django\core\management\commands\runserver.py", line 105, in inner_run
    self.validate(display_num_errors=True)
  File "C:\lib\site-packages\django\core\management\base.py", line 362, in validate
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
  File "C:\lib\site-packages\django\core\management\base.py", line 371, in check
    all_issues = checks.run_checks(app_configs=app_configs, tags=tags)
  File "C:\lib\site-packages\django\core\checks\registry.py", line 59, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\lib\site-packages\django\contrib\auth\checks.py", line 12, in check_user_model
    cls = apps.get_model(settings.AUTH_USER_MODEL)
  File "C:\lib\site-packages\django\apps\registry.py", line 202, in get_model
    return self.get_app_config(app_label).get_model(model_name.lower())
  File "C:\lib\site-packages\django\apps\config.py", line 166, in get_model
    "App '%s' doesn't have a '%s' model." % (self.label, model_name))
LookupError: App 'app1' doesn't have a 'models' model.

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:5)

AUTH_USER_MODEL设置的格式应为<app name>.<model>。您的型号名称为User,而非model,因此您的设置应为:

AUTH_USER_MODEL = 'app1.User'

您还应该从User删除以下models.py导入内容。您只需导入AbstractUser

from django.contrib.auth.models import User