2
votes

I am using Django 1.11 to build an user account application. My urls for my account app is as Code 1 as below. And also I have a templates/registrations folder and several template files there: enter image description here

After I input the email address and I receive the email with the following link: http://127.0.0.1:8000/account/password-reset/confirm/MQ/4ra-66d3672f1d340589fbf9/

I click the above link and the browser redirects to this link: http://127.0.0.1:8000/account/password-reset/confirm/MQ/set-password/

And the error prompts:

NoReverseMatch at /account/password-reset/confirm/MQ/set-password/

Reverse for 'password_reset_confirm' with no arguments not found. 1 pattern(s) tried: ['account/password-reset/confirm/(?P[-\w]+)/(?P[-\w]+)/$'] Request Method: GET Request URL: http://127.0.0.1:8000/account/password-reset/confirm/MQ/set-password/ Django Version: 1.11.7 Exception Type: NoReverseMatch Exception Value:
Reverse for 'password_reset_confirm' with no arguments not found. 1 pattern(s) tried: ['account/password-reset/confirm/(?P[-\w]+)/(?P[-\w]+)/$']

Please help me how to solve this problem. It seems that after I click the link, the Django fails to render the password_reset_confirm.html under templates/registration folder.

Code 1:

    # restore password urls
    url(r'^password-reset/$', auth_views.PasswordResetView.as_view(), name='password_reset'),
    url(r'^password-reset/done/$', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    url(r'^password-reset/confirm/(?P<uidb64>[-\w]+)/(?P<token>[-\w]+)/$',
        auth_views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),
    url(r'^password-reset/complete/$',
        auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
4

4 Answers

2
votes

Django's error message is saying that your code has tried to reverse password_reset_confirm to its url, but you haven't supplied the uid64 and token arguments that the url pattern requires. You should locate the section of your code where you perform the reverse() and update it to supply the arguments:

reverse('password_reset_confirm',args=(uid64, token))
1
votes

urls.py:

path('accounts/reset_password_confirm/<uidb64>/<token>/', PasswordResetConfirmView.as_view(), name='reset_password_confirm'),

Changing URL as above worked for me. Although, I am still not getting email. The error disappeared.

1
votes

Go to the password reset confirm template file and get rid off the action on the form like this

<form   method="post"> </form> 

instead of this :

<form   action={% url 'your template file name'%} method="post"></form>
0
votes
path('users/password_reset/', PasswordResetView.as_view(
    template_name='commons/password_reset_form.html',
    subject_template_name='commons/password_reset_subject.txt',
    email_template_name='commons/password_reset_email.html',
    success_url='done',), name="password_reset"),

path('users/password_reset/done/', 
    PasswordResetDoneView.as_view(
    template_name='commons/password_reset_done.html'),name="password_reset_done"),

path('users/reset/<uidb64>/<token>/', PasswordResetConfirmView.as_view(
    template_name='commons/password_reset_confirm.html',
    success_url='/users/reset/done/'),name="password_reset_confirm"),

path('users/reset/done/',
    PasswordResetCompleteView.as_view(template_name='commons/password_reset_complete.html'),
    name="password_reset_complete"),