Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django - no reverse match for login view

Tags:

django

I am just trying out django and following the documentation for authentication.

Basically I want to take a look at the user login form page, but I am getting:

Caught NoReverseMatch while rendering: Reverse for ''django.contrib.auth.views.login'' with arguments '()' and keyword arguments '{}' not found.

My urls.py file:

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

urlpatterns = patterns('',
    url(r'^accounts/login/$', 'django.contrib.auth.views.login'),
)

My settings.py (INSTALLED_APPS)

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)

EDIT: I realized I was looking at the wrong thing. The error occurs in the template file:

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
    <td>{{ form.username.label_tag }}</td>
    <td>{{ form.username }}</td>
</tr>
<tr>
    <td>{{ form.password.label_tag }}</td>
    <td>{{ form.password }}</td>
</tr>
</table>

<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>

Specifically for the line:

<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
like image 265
AlexBrand Avatar asked Dec 25 '11 17:12

AlexBrand


3 Answers

Try set name for url and use it in url tag:

url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'),

and in template:

<form method="post" action="{% url 'login' %}">
like image 62
ssbb Avatar answered Nov 03 '22 09:11

ssbb


Try this:

url(r'^accounts/login$', 'django.contrib.auth.views.login'),

And after your edit:

<form method="post" action="{% url django.contrib.auth.views.login %}">

EDIT in settings.py file of django, this line:

APPEND_SLASH = False

tells whether your reverse url finish with slash or not. Then

APPEND_SLASH = True
url(r'^accounts/login/', 'django.contrib.auth.views.login')

should work as well.

like image 19
asdf_enel_hak Avatar answered Nov 03 '22 10:11

asdf_enel_hak


Try adding name='login' as a keyword inthe url

url(r'^accounts/login/$', 'django.contrib.auth.views.login', name='login'),

and then calling reverse('login').

like image 5
JeffS Avatar answered Nov 03 '22 09:11

JeffS