我收到错误 CSRF 验证失败。尝试提交表单时,请求已中止。
。我已经使用了 GET 方法,但出现错误。为了确定起见,我还添加了 {% csrf_token %}
token ,但错误仍然存在。
示例 HTML:
<body>
<form action="/entry/" method="get" name="Form1"><br>
{% csrf_token %}
<select name="Date" size="1">
<option>30</option>
</select>
<select name="Month">
<option>09</option>
</select>
<select name="Year">
<option>2015</option>
</select>
<input id="Save" style="height: 50px; width: 100px;" type="submit" value="Save">
</form>
</body>
views.py 文件
def getuser(request):
return render(request, 'index.html')
def putrecord(request):
date = request.GET['Date']
print date
month = request.GET['Month']
year = request.GET['Year']
time_stamp = date + '/' + month + '/' + year
print time_stamp
return render(request, 'index.html', {})
url.py
urlpatterns = patterns('',
url(r'^expenseapp/', getuser),
url(r'^entry/', putrecord),
)
我的设置文件中还有CsrfViewMiddleware
。我怎样才能摆脱这个错误?
最佳答案
尝试从浏览器中删除cookie,CSRF使用cookie来存储 token 。
关于python - GET 表单方法上的 CSRF 验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32920532/