我已成功地生成密碼重置鏈接並使用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