0

我是django、django-rest-framework、django-allaut 和 dj-rest-auth 的新手。我正在使用邮递员注册用户,用户成功保存在数据库中,我收到一条消息说

{
    "detail": "Verification e-mail sent."
}

我的电子邮件配置如下(发送电子邮件验证时都不起作用):第一次尝试

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.mailtrap.io'
EMAIL_HOST_USER = {{my_mailtraip_user}}
EMAIL_HOST_PASSWORD = {{my_mailtraip_pass}}
EMAIL_PORT = '2525'
EMAIL_USE_TLS = True

然后尝试:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = {{my_gmail_address}}
EMAIL_HOST_PASSWORD = {{my_gmail_password}}
EMAIL_PORT = 465
EMAIL_USE_TLS = True

在我的项目应用程序中,urls.py:

path('api/accounts/', include('account.urls')),
path('api/accounts/', include('allauth.urls')),

帐户应用程序 urls.py:

    path('dj-rest-auth/', include('dj_rest_auth.urls')),
    path(
        'dj-rest-auth/registration/',
        include('dj_rest_auth.registration.urls')
    ),
    path('dj-rest-auth/account-confirm-email/',
        VerifyEmailView.as_view(), 
        name='account_email_verification_sent'
    ),

设置.py

SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED=True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
REST_USE_JWT = True

INSTALLED_APPS = [
    ...

    'django.contrib.messages',
    'django.contrib.sites',

    ...

    'rest_framework',
    'rest_framework.authtoken',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',

    'dj_rest_auth',
    'dj_rest_auth.registration',
]

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ),
}
AUTHENTICATION_BACKENDS = (
   "django.contrib.auth.backends.ModelBackend",
   "allauth.account.auth_backends.AuthenticationBackend",
)

What am I missing or failing to understand? Why is the email not sent to mailtrap? Why am not getting the key?
4

1 回答 1

0

我从PolishCoder得到了解决方案

最初我认为这是由于一些错误的配置。

于 2020-11-14T10:27:14.387 回答