Home:ALL Converter>How to properly use the django built-in login view

How to properly use the django built-in login view

Ask Time:2012-06-01T12:41:59         Author:Gabriel Burns

Json Formatter

I'm just getting started with Django, and I'm trying to use built-in features as much as possible. As such, for user login, I'm using the built-in login view, and assigning it to the base url of my site:

urlpatterns=patterns('django.contrib.auth.views',
    url(r'^/$','login',{'template':'mytemplate.html'}),

mytemplate.html looks something like this:

<!DOCTYPE html>
<html>
<body>
    {%if form.errors %}
    <p> Invalid username/password combination, please try again </p>
    {% endif %}

    <h1>Welcome to My Site!</h1>
    <form action="{% url django.contrib.auth.views.login %}" method="post">
    {% csrf_token %}
        {{form.username.label_tag}}{{form.username}}
        {{form.password.label_tag}}{{form.password}}
        <input type="submit" id="submit" name="submit" value="Sign in" />
        <input type="hidden" name="next" value="{{ next }}" />        
    </form>
    <a href="password_reset/" id="forgot"> forgot username/password</a><br />
    <a href="register" id="new">new user</a>
</body>
</html>

my problem is, the template doesn't appear to be getting passed any of the context it's supposed to. In the rendered HTML, all of my variable tags simply disappear (i.e. rather than being replaced by the appropriate values, thay are replaced with nothing).

I imagine I'm skipping some critical step, but I can't figure out what it is. Any ideas?

Author:Gabriel Burns,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/10844503/how-to-properly-use-the-django-built-in-login-view
Repede :

You need to change from 'template' to 'template_name'\n\nurlpatterns=patterns('django.contrib.auth.views',\n url(r'^/$','login',{'template_name':'mytemplate.html'}),\n\n\nhttps://docs.djangoproject.com/en/1.4/topics/auth/#django.contrib.auth.views.login",
2012-08-09T09:53:02
yy