django-allauth 没有名为 'django.core.email' 的模块
django-allauth No module named 'django.core.email'
我安装了 django-allauth,我可以使用我的管理员超级用户帐户登录和注销。但是,当我尝试注册时,出现以下错误:
ModuleNotFoundError at /accounts/signup/
No module named 'django.core.email'
在我的 settings.py 中包含配置:
SITE_ID = 1
# django-allauth configuration
LOGIN_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_REDIRECT = 'home'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
# configure email
EMAIL_BACKEND = 'django.core.email.backends.console.EmailBackend'
我没有帐户的 urls.py 或 views.py 文件,因为这是由 allauth 插件处理的。
完整的追溯是:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/signup/
Django Version: 3.2.6
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django_select2',
'crispy_forms',
'rest_framework',
'allauth',
'allauth.account',
'accounts',
'gradebook']
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 "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 230, in dispatch
return super(SignupView, self).dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 74, in dispatch
response = super(RedirectAuthenticatedUserMixin, self).dispatch(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 204, in dispatch
return super(CloseableSignupMixin, self).dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 102, in post
response = self.form_valid(form)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 248, in form_valid
return complete_signup(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 209, in complete_signup
return perform_login(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 172, in perform_login
send_email_confirmation(request, user, signup=signup, email=email)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 346, in send_email_confirmation
email_address.send_confirmation(request, signup=signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\models.py", line 62, in send_confirmation
confirmation.send(request, signup=signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\models.py", line 169, in send
get_adapter(request).send_confirmation_mail(request, self, signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\adapter.py", line 464, in send_confirmation_mail
self.send_mail(email_template, emailconfirmation.email_address.email, ctx)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\adapter.py", line 136, in send_mail
msg.send()
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\message.py", line 241, in get_connection
self.connection = get_connection(fail_silently=fail_silently)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\__init__.py", line 34, in get_connection
klass = import_string(backend or settings.EMAIL_BACKEND)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "c:\users\doug\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
<source code not available>
Exception Type: ModuleNotFoundError at /accounts/signup/
Exception Value: No module named 'django.core.email'
正确的用法应该是 mail
而不是 https://docs.djangoproject.com/en/3.2/topics/email/#console-backend 中记录的 email
因此在导入不存在的 email
模块时代码中出现错误。
替换您的设置:
EMAIL_BACKEND = 'django.core.email.backends.console.EmailBackend'
收件人:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
我安装了 django-allauth,我可以使用我的管理员超级用户帐户登录和注销。但是,当我尝试注册时,出现以下错误:
ModuleNotFoundError at /accounts/signup/
No module named 'django.core.email'
在我的 settings.py 中包含配置:
SITE_ID = 1
# django-allauth configuration
LOGIN_REDIRECT_URL = 'home'
ACCOUNT_LOGOUT_REDIRECT = 'home'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = False
# configure email
EMAIL_BACKEND = 'django.core.email.backends.console.EmailBackend'
我没有帐户的 urls.py 或 views.py 文件,因为这是由 allauth 插件处理的。
完整的追溯是:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/accounts/signup/
Django Version: 3.2.6
Python Version: 3.8.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django_select2',
'crispy_forms',
'rest_framework',
'allauth',
'allauth.account',
'accounts',
'gradebook']
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 "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\decorators\debug.py", line 89, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 230, in dispatch
return super(SignupView, self).dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 74, in dispatch
response = super(RedirectAuthenticatedUserMixin, self).dispatch(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 204, in dispatch
return super(CloseableSignupMixin, self).dispatch(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 102, in post
response = self.form_valid(form)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\views.py", line 248, in form_valid
return complete_signup(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 209, in complete_signup
return perform_login(
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 172, in perform_login
send_email_confirmation(request, user, signup=signup, email=email)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\utils.py", line 346, in send_email_confirmation
email_address.send_confirmation(request, signup=signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\models.py", line 62, in send_confirmation
confirmation.send(request, signup=signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\models.py", line 169, in send
get_adapter(request).send_confirmation_mail(request, self, signup)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\adapter.py", line 464, in send_confirmation_mail
self.send_mail(email_template, emailconfirmation.email_address.email, ctx)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\allauth\account\adapter.py", line 136, in send_mail
msg.send()
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\message.py", line 284, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\message.py", line 241, in get_connection
self.connection = get_connection(fail_silently=fail_silently)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\core\mail\__init__.py", line 34, in get_connection
klass = import_string(backend or settings.EMAIL_BACKEND)
File "C:\Users\Doug\.virtualenvs\upgradetools-YX5Y8vBO\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "c:\users\doug\appdata\local\programs\python\python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
<source code not available>
Exception Type: ModuleNotFoundError at /accounts/signup/
Exception Value: No module named 'django.core.email'
正确的用法应该是 mail
而不是 https://docs.djangoproject.com/en/3.2/topics/email/#console-backend 中记录的 email
因此在导入不存在的 email
模块时代码中出现错误。
替换您的设置:
EMAIL_BACKEND = 'django.core.email.backends.console.EmailBackend'
收件人:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'