【发布时间】:2022-07-19 21:02:19
【问题描述】:
我安装了一个名为“Login”的应用程序,其中有一个文件夹“models”,其中包含一个 custom_user 模型。当我尝试配置 settings.py,特别是 auth_user_model 时出现问题。
在已安装的应用程序中,我有以下内容:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'project_app.login'
]
及以下
AUTH_USER_MODEL = 'login.models.CustomUser'
但我有以下错误:“无效的模型引用。字符串模型引用必须采用 'app_label.ModelName' 的形式。”我将 .models 放在 AUTH_USER_MODEL 中,因为我想在 Login 中引用 CustomUser 位于文件夹“models”中的应用程序。
另外,我尝试过这样声明:
AUTH_USER_MODEL = 'login.CustomUser'
但错误是这样的:'AUTH_USER_MODEL 指的是尚未安装的模型'login.CustomUser''
【问题讨论】:
标签: django authentication settings