Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoReverseMatch Error

I keep getting this error for the django login system. Here is part of my urls.py:

     (r'^contractManagement/login', 'django.contrib.auth.views.login', {'template_name': 'login.html'}), 

The exact error I am getting:

Exception Type: NoReverseMatch Exception Value:    Reverse for ''django.contrib.auth.views.login'' with arguments '()' and keyword arguments '{}' not found. 

I can't understand why i am getting this error. If you need anything else let me know.

like image 966
Dean Avatar asked Feb 12 '11 22:02

Dean


People also ask

What does NoReverseMatch mean?

NoReverseMatch (source code) is a Django exception that is raised when a URL cannot be matched against any string or regular express in your URL configuration. A URL matching problem is often caused by missing arguments or supplying too many arguments.

How do I get an absolute url in Django?

Use handy request. build_absolute_uri() method on request, pass it the relative url and it'll give you full one. By default, the absolute URL for request. get_full_path() is returned, but you can pass it a relative URL as the first argument to convert it to an absolute URL.

What is reverse function in Django?

the reverse function allows to retrieve url details from url's.py file through the name value provided there. This is the major use of reverse function in Django. Syntax: Web development, programming languages, Software testing & others. from django.urls import reverse.


2 Answers

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' %} 
like image 152
Daniel Roseman Avatar answered Oct 01 '22 14:10

Daniel Roseman


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 %} 
like image 36
hynekcer Avatar answered Oct 01 '22 13:10

hynekcer