Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse for 'login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

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...

like image 751
jsanchezs Avatar asked Dec 19 '22 21:12

jsanchezs


1 Answers

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'),
]
like image 142
knbk Avatar answered Dec 21 '22 09:12

knbk