Django 2 Allauth电子邮件确认重定向到空白页

时间:2019-03-10 13:04:53

标签: django django-views django-allauth

我正在尝试设置allauth,至少可以说是一个挑战。

我的注册页面有效(尽管username字段拒绝出现在表单上),并且在提交后,将用户重定向到带有标有Check your email to confirm account的标语的空白页面。

电子邮件中说

To confirm this is correct, go to http://localhost:8000/users/verify-email/Ng:1h2xx7:z9x0t0wmvAhicak5twI_QtVWNYo

当我单击链接时,页面为空(尽管仍由我的base.html设置样式,但没有内容。)

我假设它应该指向登录页面并显示横幅Account confirmed, you may now log in.

有人可以告诉我为什么会这样吗?

确认电子邮件确认后,该页面是否有views.py类?

urls.py

from django.contrib.auth import views as auth_views
from users import views as user_views
from allauth.account.views import confirm_email

urlpatterns = [
    path('register', user_views.MySignupView.as_view(template_name='users/register.html'), name='register'),
    path('login', user_views.MyLoginView.as_view(template_name='users/login.html'), name='login'),
    path('verify-email/<str:key>',
    confirm_email,
    name='account_confirm_email'),

views.py

from allauth.account.views import SignupView, LoginView

class MySignupView(SignupView):
    template_name = 'users/register.html'

class MyLoginView(LoginView):
    template_name = 'users/login.html'

forms.py

class UserRegisterForm(forms.Form):
    email = forms.EmailField()
    first_name = forms.CharField(required=True)
    last_name = forms.CharField(required=True)

    def signup(self, request, user):
        user.first_name = self.cleaned_data['first_name']
        user.last_name = self.cleaned_data['last_name']
        user.save()

settings.py

ACCOUNT_SIGNUP_FORM_CLASS = 'users.forms.UserRegisterForm'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS=7
ACCOUNT_LOGIN_ATTEMPTS_LIMIT = 5
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400 # 1 day in seconds

1 个答案:

答案 0 :(得分:0)

结果证明我使用的是{% block body %}而不是{% block content %},因此页面被设置为样式但为空。