Question

I am following the getting started guide for Django registration and I am getting the following error when I visit http://localhost:8080/accounts/register/ :

NoReverseMatch at /accounts/register/
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL:    http://localhost:8080/accounts/register/
Django Version: 1.5.1
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
Exception Location: /Library/Python/2.7/site-packages/django/template/defaulttags.py in render, line 424
Python Executable:  /usr/bin/python
Python Version: 2.7.1
Python Path:    
['/Users/Studio/Desktop/orro/t1/tut',
 '/Library/Python/2.7/site-packages/setuptools-0.9.8-py2.7.egg',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages']
Server time:    Mon, 12 Aug 2013 18:53:54 -0500
Error during template rendering

In template /Users/Studio/Desktop/pod/t1/tut/tut/templates/base.html, error at line 16
Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.
6   <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7   
8   <head>
9       <link rel="stylesheet" href="/style.css" />
10      <title>{% block title %}User test{% endblock %}</title>
11  </head>
12  
13  <body>
14      <div id="header">
15          {% block header %}
16      <a href="{% url 'index' %}">{% trans "Home" %}</a> |
17  
18      {% if user.is_authenticated %}
19      {% trans "Logged in" %}: {{ user.username }}
20      (<a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a> |
21      <a href="{% url 'auth_password_change' %}">{% trans "Change password" %}</a>)
22      {% else %}
23      <a href="{% url 'auth_login' %}">{% trans "Log in" %}</a>
24      {% endif %}
25      <hr />
26          {% endblock %}

My urls.py:

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'tut.views.home', name='home'),
    # url(r'^tut/', include('tut.foo.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    (r'^accounts/', include('registration.backends.default.urls', namespace='registration')),


)

Any ideas?

Was it helpful?

Solution

The information you need is in the traceback you have provided,

In template /Users/Studio/Desktop/pod/t1/tut/tut/templates/base.html, error at line 16 Reverse for 'index' with arguments '()' and keyword arguments '{}' not found.

In your base.html template, on line 16, you are using the url tag to link to the view named 'index'.

16      <a href="{% url 'index' %}">{% trans "Home" %}</a> |

However, there is no url pattern named index in your url patterns. Therefore the reverse fails, and raises a NoReverseMatch exception.

You can fix this by creating an index view in your tut.views module, and adding it to your url patterns.

url(r'^$', 'tut.views.index', name='index'),

Alternatively, you can remove the {% url 'index' %} from your template until you add an index view.

OTHER TIPS

add url(r'^', include('django.contrib.auth.urls')) to url patterns

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top