Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4455623
  • 博文数量: 1214
  • 博客积分: 13195
  • 博客等级: 上将
  • 技术积分: 9105
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-19 14:41
个人简介

C++,python,热爱算法和机器学习

文章分类

全部博文(1214)

文章存档

2021年(13)

2020年(49)

2019年(14)

2018年(27)

2017年(69)

2016年(100)

2015年(106)

2014年(240)

2013年(5)

2012年(193)

2011年(155)

2010年(93)

2009年(62)

2008年(51)

2007年(37)

分类: Python/Ruby

2012-06-18 00:29:26

文章来源:

I was getting this 403 error today while attempting to make a POST request to a view:

403 Forbidden

CSRF verification failed. Request aborted.

Help Reason given for failure:

CSRF cookie not set.

Edit 10/29/2010 I’ve modified this post to only contain the proper way of resolving the issue. You can read about Cross Site Request Forgeries here and Django’s protection mechanisms here

To resolve the 403 issue, you want to add the csrf_token template tag within your form somewhere. This adds a hidden div with the value of the input as the csrf token:

anything.html
1 2 3 4 action="..." method="POST"> {% csrf_token %} ...

If you’d like to not protect against CSRF with Django’s built in mechanisms, use the csrf_exempt decorator:

views.py
1 2 3 4 5 from django.views.decorators.csrf import csrf_exempt ... @csrf_exempt def my_func(request): ...

May 24th, 2010


阅读(1481) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~