I'm trying to implement a login page using the django login view, here is the code :
urls.py
urlpatterns = patterns(
'',
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^logout/$', 'django.contrib.auth.views.logout'),
)
and the template:
login.html
{% extends 'base_cost_control.html' %}
{% block contentbase %}
{% if form.errors %}
<p>Invalid user or password</p>
{% endif %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<div class="row" align="center">
<br>
<br>
<h3> CONTROL DE COSTOS </h3>
<br><br>
<table>
<tr>
<td width=700px>{%include "partials/field.html" with field=form.username %}</td>
</tr>
<tr>
<td width=700px>{%include "partials/field.html" with field=form.password %}</td>
</tr>
<tr>
<td align="right"><input type="submit" class="btn btn-info" name = "siguiente" id="siguiente" value="Ingresar"/></td>
</tr>
</table>
</div>
</form>
{% endblock contentbase %}
So, I know django.contrib,auth.views.login generates the view and I only have to create the login.html template, but I get this error at line 8 in login.html:
Reverse for 'login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I don know what else to do...
You haven't named the login url, so you can't reverse it by the name login
. Just add the name to the pattern:
from django.contrib.auth import views as auth_views
urlpatterns = [
url(r'^login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
]
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