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' %}">
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' %}">
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.
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').
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With