0

Under Django 1.8. I added a namespace to my app but now I have problem with registrations pages.

Url: http://127.0.0.1:8000/accounts/password_reset/

in myapp/urls.py:

  ...
  from django.contrib.auth.views import password_reset, password_reset_done
  ...

  # include registration app urls 
  url(r'^accounts/', include('registration.urls')),


  url(r'^accounts/password_reset/$', password_reset,
      {'template_name': 'registration/password_reset.html'},
      name='reset-password'),

  url(r'^accounts/password_reset_success/$', password_reset_done,
       {'template_name': 'registration/password_reset_done.html'},
       name="password_reset_done"),

Error:

NoReverseMatch at /accounts/password_reset/
Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

In project/urls/myapp.py:

url(r'^', include('myapp.urls',
    namespace='myapp', app_name='myapp')),

in django.contrib.auth.views password_reset :

If I replace

if post_reset_redirect is None:
    post_reset_redirect = reverse('password_reset_done')
else:
    post_reset_redirect = resolve_url(post_reset_redirect)
if request.method == "POST":

** with **

if post_reset_redirect is None:
    post_reset_redirect = reverse('myapp:password_reset_done')
else:
    post_reset_redirect = resolve_url(post_reset_redirect)
if request.method == "POST":

It works.

So I think I have to pass the namespace to the registrations urls somewhere.

kollo
  • 1,285
  • 3
  • 20
  • 33
  • since you haven't added your view, I would recommend to add a name for your app app_name = 'accounts' in your urlss.py and then use it as following accounts:password_reset_done – Hozayfa El Rifai Jun 08 '18 at 15:45
  • Note that Django 1.8 is end of life and does not receive security updates. – Alasdair Jun 08 '18 at 16:32

2 Answers2

0

You can set a custom post_reset_redirect in your URL config when you include the password_reset view:

url(r'^accounts/password_reset/$', password_reset,
  {'template_name': 'registration/password_reset.html', 'post_reset_redirect': reverse_lazy('myapp:password_reset_done')},
  name='reset-password'),

However, I think you'll find that using a namespace requires changes in other parts of the password reset process as well (e.g. the email template). The easiest solution is not to use a namespace for this app.

Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thanks! Didn't know about how to pass post_reset_redirect. Seems to works fine, will dig to see if all is ok. Btw I know Django 1.8 is depreciated , have to upgrade someday. – kollo Jun 08 '18 at 16:44
0

When using class based view the param name changes, you need to use success_url:

    path(
    '/password/reset/',
    auth_views.PasswordResetView.as_view(
        template_name='registration/password_reset.html',
        success_url=reverse_lazy('account:password-reset-done')),
    name='password-reset'),
abidibo
  • 4,175
  • 2
  • 25
  • 33