[Django]-NoReverseMatch Error

44đź‘Ť

âś…

You don’t show where you are trying to reverse this URL, but it looks like you have double-quoted it. If you’re using the url tag, note that you don’t need quotes around the url name:

{% url django.contrib.auth.views.login %}

not

{% url 'django.contrib.auth.views.login' %}

19đź‘Ť

You see that ''the.unknown.view'' is reported including too many qoutes.

It is because the quoted syntax will be valid in Django 1.5 and higher. For Django 1.3 or 1.4, you should activate the future behavior by this line in the template:

{% load url from future %}

which is valid also for Django 1.5.


Example for Django 1.5+

{% url "path.to.some.view" %}

Classic syntax for Django <= 1.4.x (without “future” command) is:

{% url path.to.some.view %}
👤hynekcer

6đź‘Ť

I would give your url a name (in order to do that, you need to use the url method) Also you should add a trailing slash to all your urls, cause the django CommonMiddleware is going to be doing a 302 redirect on all your urls if you don’t:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
     url(r'^contractManagement/login/', 'django.contrib.auth.views.login', {'template_name': 'login.html'}, name='contract_login'),

)

Then you can use reverse in your code, or url in your templates, and if you ever decide to change the actual url (ie: changedCotractManagement/login/), as long as the name is the same, your code will still be good.

in code:

from django.core.urlresolvers import reverse
reverse('contract_login')

in template:

{% url contract_login %}

Edit: per MrOodles

👤MattoTodd

Leave a comment