在我的Django项目中,我的urls.py
中包含以下内容:
urlpatterns = [
path('register/', views.register, name='register'), # Registration
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'), # Login Page
path('logout/', auth_views.LogoutView.as_view(next_page='misc:index'), name='logout'), # Logout Page
path('change_password/', auth_views.PasswordChangeView.as_view(template_name='users/change_password.html', success_url='/'), name='change_password'), # Password Change Page
# Password reset pages; They take a lot of parameters
path('reset_password/', auth_views.PasswordResetView.as_view(
template_name='users/password_reset/password_reset_request.html',
email_template_name='users/password_reset/email_password_reset.html',
subject_template_name='users/password_reset/email_password_reset_subject.txt',
success_url='/reset_password/check_your_email/',
from_email='password-reset@sn.local',
html_email_template_name='users/password_reset/email_password_reset.html'
), name='password_reset_request'),
path('reset_password/check_your_email/', views.password_reset_check_your_email, name='password_reset_check_your_email'),
path('reset_password/<uidb64>/<slug:token>/', auth_views.PasswordResetConfirmView.as_view(
template_name='users/password_reset/password_reset_form.html',
post_reset_login=True,
success_url='/'), name='password_reset_form'),
]
所有网址都可以正常工作,但最后一个网址没有反向匹配错误。
我要使用的网址是:http://127.0.0.1:8000/reset_password/bAAAAAA/52s-c48e21c49899996ec19c/
当我尝试访问它时,它给了我这个错误:
Reverse for 'password_reset_form' with keyword arguments '{'uidb64': '', 'token': ''}' not found. 1 pattern(s) tried: ['reset_password/(?P<uidb64>[^/]+)/(?P<token>[-a-zA-Z0-9_]+)/$']
编辑:
users/password_reset/password_reset_form.html
{% extends 'base.html' %}
{% block title %}Reset Password{% endblock title %}
{% block content %}
<form action="{% url 'users:password_reset_form' uidb64=uidb64 token=token %}" method="post">
{% csrf_token %}
{{ form.as_p }}
<button name="submit" class="btn btn-primary">Reset Password</button>
</form>
{% endblock content %}
我觉得我在这里遗漏了一些东西...
任何帮助将不胜感激
答案 0 :(得分:0)
PasswordResetConfirmView不会将uidb64
或token
的值发送到模板上下文,这就是为什么它们在该错误消息中显示为空白的原因。
但是您不需要它们。表单只是发回到最初显示它的URL。因此,只需:
<form action="" method="post">