python - Django : LookupError: App ' doesn' t have a 'models' model

标签 python django

enter image description here

我正在处理 https://bixly.com/blog/awesome-forms-django-crispy-forms/ ,尝试使用 django crispy forms 设置 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.

我该如何解决这个问题?

最佳答案

AUTH_USER_MODEL设置的格式应为 <app name>.<model> .您的型号名称是 User , 不是 model ,所以你的设置应该是:

AUTH_USER_MODEL = 'app1.User'

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

from django.contrib.auth.models import User

关于python - Django : LookupError: App ' doesn' t have a 'models' model,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38665252/

相关文章:

python - numpy 数组的 Cython 开销

django - 仅在 django admin 中显示年份,YearField 而不是 DateField?

python - 如何模拟 ManyToMany 字段?

python - Django DetailView 动态模型

django - TableBlock 如何指定表格 CSS 类

python - Django 休息 : Uploading and serializing multiple images

python - 如何在 python 中去除文件中文本中的\n,然后计算文本中包含超过 n 个字母的单词?

python - 将白色背景更改为特定颜色

python - 在python中更新数据库中的数据

python - Sphinx 不会自动记录装饰的 Celery 任务