我已成功地生成密码重置链接并使用django内置密码重置将它们发送到邮件,并且还在需要时使用了我自己的模板。
上面是我在我的测试项目中实现它的情况(只是为了不打破我的实际项目)。但是当我复制从测试项目,项目实际粘贴我的代码,有在代重置密码的更改链接
令牌时,在我的测试项目工作Django 1.11意外更改密码重置令牌的生成
令牌什么时候在我的实际项目中工作
有变化MQ-和Mg/
我的问题:
1)我无法在URL匹配正则表达式,并显示我的模板,而不是Django的默认模板,正在显示
url(r'^reset/password/success/$', AuthHandler().reset_success, name="auth.success"),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>.+)/$',AuthHandler().reset_password, name="password_reset_confirm"),
url(r'^reset/done/$', auth_views.password_reset_complete,name="auth.complete"),
在view.py
def forgot_password(self, request):
# Forgot password form
try:
error_flag = True
if request.method == "GET":
error_flag = False
form = auth.ForgotPassword()
return auth_views.password_reset(
request, template_name='forgot_password.html',
extra_context={'form': form, 'error': error_flag},
password_reset_form=auth.EmailValidationOnForgotPassword,
post_reset_redirect='auth.success',
)
except Exception as e:
print(e)
def reset_success(self, request):
# Reset email sent to email
try:
return auth_views.password_reset_done(request, template_name='reset_password_success.html')
except Exception as e:
print(e)
def reset_password(self, request, uidb64, token):
# Reset password page
try:
reset_form = auth.ResetPassword() # template_name='te/reset_password.html',
return auth_views.password_reset_confirm(
request,
template_name='reset_passwword_success.html',
post_reset_redirect='auth.success', current_app=None,
extra_context=None)
except Exception as e:
print(e)
的问题是我UNA可以进入reset_password功能页面,从而显示我的模板,其中显示了django默认值。但我能够在我的测试项目中工作(在URL的正则表达式中使用' - ')
2)为什么Django会生成两个完全不同的链接,其中一个是/和另一个没有它。 (据我所知,没有哈希应该有/在里面)。
我讨厌是表明一个包,而不是回答你的问题的家伙,但...你可以尝试Django的密码重置。我用过,而且运行起来非常简单。 – DragonBobZ
我倾向于同意这样的想法,即一个散列,至少是一个URL中使用的散列,不应该有一个'/'。也许你可以把这个问题带到Django的邮件列表中,或者提交关于它的一张票。 – Evert