django-open-id: CSRF verification failed
I fallowed recommendation in this SO question: What's the best solution for OpenID with Django? and installed django-openid-auth
for my application.
But I just can't get it working, I always get CSRF verification failed. Request aborted.
when I try to log in.
I have checked everything:
1.
{% csrf_token %}
is present in the template:
<form name="fopenid" action="{{ action }}" method="post">
{% csrf_token %}
<fieldset>
<legend>Sign In Using Your OpenID</legend>
<div class="form-row">
<label for="id_openid_identifier">OpenID:</label><br />
{{ form.openid_identifier }}
</div>
<div class="submit-row ">
<input name="bsignin" type="submit" value="Log in">
</div>
{% if next %}
<input type="hidden" name="next" value="{{ next }}" />
{% endif %}
</fieldset>
</form>
2.
In the views.py inside of django_openid_auth
I found, that they use RequestContext
:
return render_to_response(template_name, {
'form': login_form,
redirect_field_name: redirect_to
}, context_instance=RequestContext(request))
3.
My MIDDLEWARE_CLASSES
does contain CsrfViewMiddleware
:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
I just can't understand what else could be wrong? Do you have any ideas?
I am using Django 1.3 beta.
UPDATE
This seem to be my global problem. I've created a simple form and got the same result:
def index(request):
return render_to_response('index.html',
locals(),
context_instance=RequestContext(request))
index.html:
<form action="/" method="post">
{% csrf_token %}
<input type="text" name="test">
<input type="submit">
</form>
Rendered HTML:
<form action="/" method="post">
<div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="1fbd5345560d325bf05809260f7d43c3"></div>
<input typ开发者_开发百科e="text" name="test">
<input type="submit">
</form>
What's wrong!?
I tried "manage.py runserver localhost:8000" instead of "manage.py runserver" and it worked my guess is it has some cookie problems because of ip in hostname btw. i got this error with fresh copy of django 1.3
Actually, I think it was the first bug I encountered in Django. I've updated my copy to fresh release of 1.3 and everything started working. Good job, Django developers!
精彩评论