views:

81

answers:

2

In my base.html I placed this:

{% if user.is_authenticated %}
you are logged in!
{% else %}
<h3>Login</h3>
<form action="/login/" method="post" accept-charset="utf-8">
<label for="username">Username</label><input type="text" name="username" value="" id="username" />
<label for="password">Password</label><input type="password" name="password" value="" id="password" />
<p><input type="submit" value="Login →"></p>
</form>
{% endif %}

In urls.py:

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

When I accessed /login I had to make a login.html file. I created templates/registration/login.html:

{% extends "base.html" %}

{% block content %}

{% if form.errors %}
<p>Your username/pass didnt match</p>
{% endif %}

{% endblock %}

I'm not seeing the username/pass, but I'm still seeing the meaning my user is not authenticated yet.

Btw, I don't have the CSRF middleware loaded. Did I miss a step or two?

One other thing, I accessed logout.html and it went into my django admin logout page. I tried making a templates/registration/logout.html but it didn't override that part. Hrm?

+2  A: 

Are you passing the user variable to your template context? Either explicitly, or via a context processor?

Daniel Roseman
I'm not passing the `user` variable explicitly but I don't get any warnings that there is no `user` object so I assume it's getting passed through some means.
meder
Django templates don't warn if a template isn't present, they just fail silently. So if you're not passing it (or, as I say, using the context processor), it's not there. Try just outputting the value of `{{ user }}` to see for sure.
Daniel Roseman
Says `AnonymousUser`
meder
A: 

Doh. Apparently my actual template had action="/login" but when I typed it in the example here it had an end slash, I re-added the end slash and that was it.

meder