没有名为 'account' 的模块

No module named 'account'

ModuleNotFoundError/admin/login/ 没有名为 'account'

的模块

我有一个名为 users 而非 account 的应用程序。只有当我提交登录表单或转到 http://localhost:8000/admin/login/

时才会出现错误

您还可以在 https://github.com/cell20/twitter

上查看完整项目

完整追溯:


Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/

Django Version: 4.0.4
Python Version: 3.9.7
Installed Applications:
['users.apps.UsersConfig',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_extensions',
 'faker']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\utils\decorators.py", line 46, in _wrapper
    return bound_method(*args, **kwargs)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\views\decorators\cache.py", line 62, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\admin\sites.py", line 422, in login
    **self.each_context(request),
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\admin\sites.py", line 337, in each_context
    "available_apps": self.get_app_list(request),
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\admin\sites.py", line 537, in get_app_list
    app_dict = self._build_app_dict(request)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\admin\sites.py", line 477, in _build_app_dict
    has_module_perms = model_admin.has_module_permission(request)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\admin\options.py", line 606, in has_module_permission
    return request.user.has_module_perms(self.opts.app_label)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\auth\models.py", line 483, in has_module_perms
    return _user_has_module_perms(self, module)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\auth\models.py", line 230, in _user_has_module_perms
    for backend in auth.get_backends():
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\auth\__init__.py", line 38, in get_backends
    return _get_backends(return_tuples=False)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\auth\__init__.py", line 27, in _get_backends
    backend = load_backend(backend_path)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\contrib\auth\__init__.py", line 21, in load_backend
    return import_string(path)()
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\utils\module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "E:\Dev\realpython\django\projects\django-social\venv\lib\site-packages\django\utils\module_loading.py", line 15, in cached_import
    import_module(module_path)
  File "C:\Users\Suhail\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
    <source code not available>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
    <source code not available>
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
    <source code not available>
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
    <source code not available>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
    <source code not available>
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
    <source code not available>

Exception Type: ModuleNotFoundError at /admin/login/
Exception Value: No module named 'account'


settings.py 中,AUTHENTICATION_BACKENDS 中的自定义身份验证后端设置为 'account.authentication.EmailAuthBackend' 而不是 'users.authentication.EmailAuthBackend'。请确保在重试之前清除您的会话数据。