0
votes

The complete error message I'm getting is:

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

I'm trying to use the standard DJANGO auth libraries to implement signin, logoff, password reset and sign up functionality/views to my site.

I'm using the Anaconda 4.6 package and I'm importing the DJANGO libraries as below

from django.contrib.auth import views as auth_views

The (relevant) urlpatterns I have are:

url(r'^password_reset/$', auth_views.password_reset, name='password_reset'),

url(r'^password_reset/done/$', auth_views.password_reset_done, name='password_reset_done'),

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.password_reset_confirm, name='password_reset_confirm'),

url(r'^reset/done/$', auth_views.password_reset_complete, name='password_reset_complete'),

If I go to the URL

/password_reset/done/

I reach the page.

If I go to the URL

/password_reset/

I get the failed reverse error.

I've been reading the documentation for 2 days but I don't seem to be able to find out why

url(r'^password_reset/done/$', auth_views.password_reset_done, name='password_reset_done'),

is blocking the django reverse function. Does anyone have any ideas?

Thanks a lot!

Traceback here too for more details:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/password_reset/

Django Version: 1.10.5
Python Version: 3.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'bootstrap3',
 'app1']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback:

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\base.py" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\core\handlers\base.py" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\contrib\auth\views.py" in inner
  47.         return func(*args, **kwargs)

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\utils\decorators.py" in _wrapped_view
  149.                     response = view_func(request, *args, **kwargs)

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\contrib\auth\views.py" in password_reset
  189.         post_reset_redirect = reverse('password_reset_done')

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\urls\base.py" in reverse
  91.     return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)))

File "E:\Programming\Anaconda3_4.2.0\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
  392.             (lookup_view_s, args, kwargs, len(patterns), patterns)

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

Adding some additional info:

projects urls:

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^app1/',include('app1.urls')),
    url(r'^',include('app1.urls')), 
]

Template code for 'app1\registration\login.html' which renders correctly:

{% block title %}Login{% endblock %}

{% block content %}
  <h2>Login</h2>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Login</button>
  </form>
{% endblock %}

Template code for 'app1\registration\password_reset_done.html' which throws the error:

{% block content %}
  <p>
    We've emailed you instructions for setting your password, if an account exists with the email you entered.
    You should receive them shortly.
  </p>
  <p>
    If you don't receive an email, please make sure you've entered the address you registered with,
    and check your spam folder.
  </p>
{% endblock %}
1
I'm trying with python3.6 and django 1.11and an empty project, your regex in urls.py are ok, I suspect that the template that django is rendering is the problem. Have you tried to remove /admin dir in your templates directories?Tomás Gonzalez Dowling
Please share the template code where all these urls are being used.Prakhar Trivedi
Sorry for the long delay (time differences) but I've added some extra info above. I'm reviewing the template code but there isn't much to it yet.user3535074

1 Answers

3
votes

Though I'm not sure if this solution really is the best, it's enabled me to use custom templates and avoid the reverse errors by explicitly filling out the workflow in kwargs in the urls patterns of the myappurls.py:

from django.contrib.auth import views as auth_views

url(r'^login/$', auth_views.login, {'template_name': 'myapp/registration/login.html'},name='login'),
url(r'^logout/$', auth_views.logout, {'next_page': 'myapp:home'},name='logout'),

url(r'^password_reset/$', auth_views.password_reset,{'email_template_name':'myapp/registration/password_reset_email.html',
                                                    'template_name':'myapp/registration/password_reset_form.html',
                                                    'subject_template_name':'myapp/registration/password_reset_subject.txt',
                                                    'post_reset_redirect':'myapp:password_reset_done',
                                                    'from_email':'myapp@django.com',
                                                    },name='password_reset'),

url(r'^password_reset/done/$', auth_views.password_reset_done, {'template_name': 'myapp/registration/password_reset_done.html'}, name='password_reset_done'),

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.password_reset_confirm,
                                                    {'template_name': 'myapp/registration/password_reset_confirm.html',
                                                    'post_reset_redirect': 'myapp:password_reset_complete'},
                                                    name='password_reset_confirm'),

url(r'^reset/done/$', auth_views.password_reset_complete, {'template_name': 'myapp/registration/password_reset_complete.html'},name='password_reset_complete'),

UPDATED ANSWER!


Though I found a workaround to my problem in the first answer I gave, I finally understood what the real problem was.

The problem was that the namespaces were not correctly configured between my project urls.py and my myapp/urls.py. To correctly line everything up I needed to change the project urls.py to point to the app/urls.py and give it a namespace name:

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

Then in the app/urls.py I needed to assign it a namespace name for the rever method to connect the two:

app_name = 'myapp'

urlpatterns = [ url(r'password_reset/done/', auth_views.password_reset_done,name='password_reset_done'), url(r'password_reset/', auth_views.password_reset, name='password_reset'), ]

Now everything works perfectly out of the box as it should without a bucket-load of hacky parameters.