您的位置:首页 > 大数据 > 人工智能

Django 对于CSRF verification failed.错误的解决方法

2013-04-24 14:03 316 查看
当使用表单提交的时候,产生错误,错误信息如下:


Forbidden (403)

CSRF verification failed. Request aborted.

测试可行的解决方法(django文档—CSRF):

1.在模板的form中加入{% csrf_token %}

In any template that uses a POST form, use the csrf_token tag
inside the <form> element if the form is for an internal URL, e.g.:

<form action="." method="post">{% csrf_token %}


This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.

2.修改views.py,注意红色标记处

from django.shortcuts import render_to_response
from django.template import RequestContext
def sysconfig(request):
return render_to_response('SysConfig.html',locals(),RequestContext(request))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐