我对Django很陌生,我只是跟着教程。我从https://github.com/justdjango/getting-started-with-django做了一个项目,在我添加了用户和超级用户之后,我开始得到这样的Traceback:
Traceback (most recent call last):
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribauth__init__.py", line 160, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL, require_ready=False)
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangoappsregistry.py", line 204, in get_model
app_label, model_name = app_label.split('.')
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersDellDesktopprogmanage.py", line 22, in <module>
main()
File "C:UsersDellDesktopprogmanage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocoremanagement__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocoremanagement__init__.py", line 395, in execute
django.setup()
File "C:UsersDellDesktopprogprogramalibsite-packagesdjango__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangoappsregistry.py", line 122, in populate
app_config.ready()
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribadminapps.py", line 27, in ready
self.module.autodiscover()
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribadmin__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangoutilsmodule_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0libimportlib__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribauthadmin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribauthforms.py", line 21, in <module>
UserModel = get_user_model()
File "C:UsersDellDesktopprogprogramalibsite-packagesdjangocontribauth__init__.py", line 162, in get_user_model
raise ImproperlyConfigured("AUTH_USER_MODEL must be of the form 'app_label.model_name'")
django.core.exceptions.ImproperlyConfigured: AUTH_USER_MODEL must be of the form 'app_label.model_name'
您忘记在AUTH_USER_MODEL
设置中指定模型名称。如果你在leads
应用程序中定义了一个模型User
,那么你可以这样设置:
# settings.py
# app name ↓
AUTH_USER_MODEL = 'leads.User'
# model name ↑