Django:如何将价值从一个CBV传递到另一个

时间:2019-07-10 21:57:39

标签: python django django-views

我正在尝试自定义Django身份验证表单/模板。 URL / accounts / password_reset /(CBV:PasswordResetView)用于输入帐户电子邮件。表单提交后,用户重定向到/ accounts / password_reset / done /(CBV:PasswordResetDoneView)

我需要在PasswordResetDoneView中使用电子邮件值。我该怎么办?

很抱歉出现新手问题。

urls.py

from django.urls import path, include
from . import views

urlpatterns = [
    # ...
    path('accounts/password_reset/', views.CustomPasswordReset.as_view(), name='password_reset'),
    path('accounts/password_reset/done/', views.CustomPasswordResetDone.as_view(), name='password_reset_done'),
    # ...
]

views.py

from django.contrib.auth import views as auth_views
from .forms import LoginForm, ResetForm, NewPasswordForm

class CustomPasswordReset(auth_views.PasswordResetView):
    template_name = 'authorization/password_reset_form.html'
    html_email_template_name = 'authorization/password_reset_email_html.html'
    email_template_name = 'authorization/password_reset_email_plain.html'
    subject_template_name = 'authorization/password_reset_subject.txt'


class CustomPasswordResetDone(auth_views.PasswordResetDoneView):
    template_name = 'authorization/password_reset_done.html'

    # TODO. I have no idea how to get email address that was entered in 'password_reset' step
    # 
    email = 'example@gmail.com'
    mbox, mserver = email.split('@')
    extra_context = {'mserver': mserver}

0 个答案:

没有答案