[英]django-open-id: CSRF verification failed
I fallowed recommendation in this SO question: What's the best solution for OpenID with Django? 在这个SO问题中我没有推荐: Django OpenID的最佳解决方案是什么? and installed
django-openid-auth
for my application. 并为我的应用程序安装了
django-openid-auth
。
But I just can't get it working, I always get CSRF verification failed. Request aborted.
但是我只是无法正常工作,我总是使
CSRF verification failed. Request aborted.
CSRF verification failed. Request aborted.
when I try to log in. 当我尝试登录时。
I have checked everything: 我检查了所有内容:
{% csrf_token %}
is present in the template: 模板中包含
{% csrf_token %}
:
<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>
In the views.py inside of django_openid_auth
I found, that they use RequestContext
: 在我发现的
django_openid_auth
内部的views.py中,它们使用RequestContext
:
return render_to_response(template_name, {
'form': login_form,
redirect_field_name: redirect_to
}, context_instance=RequestContext(request))
My MIDDLEWARE_CLASSES
does contain CsrfViewMiddleware
: 我的
MIDDLEWARE_CLASSES
确实包含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. 我正在使用Django 1.3 beta。
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: index.html:
<form action="/" method="post">
{% csrf_token %}
<input type="text" name="test">
<input type="submit">
</form>
Rendered HTML: 呈现的HTML:
<form action="/" method="post">
<div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="1fbd5345560d325bf05809260f7d43c3"></div>
<input type="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. 我尝试使用“ manage.py runserver localhost:8000”而不是“ manage.py runserver”,它的工作原理是由于主机名btw中的ip而存在一些cookie问题。 i got this error with fresh copy of django 1.3
我在django 1.3的新副本中遇到了这个错误
Actually, I think it was the first bug I encountered in Django. 实际上,我认为这是我在Django中遇到的第一个错误。 I've updated my copy to fresh release of 1.3 and everything started working.
我已经将副本更新为1.3的新发行版,一切都开始正常工作。 Good job, Django developers!
干得好,Django开发人员!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.