我是 django-piston 的新手,由于 Django 的 CSRF 保护,无法让 POST 网络服务调用正常工作。我如何允许 web 服务调用绕过 CSRF 保护并仍然允许其余网页保留它们?
问问题
1263 次
2 回答
3
找到了解决方案:https ://bitbucket.org/jespern/django-piston/issue/82/post-requests-fail-when-using-django-trunk ,归功于 Brian Zambrano。
我觉得这有点烦人,这已经两年了,一个补丁已经创建并且仍然没有合并到最新的源中。
要修复它,请通过添加self.csrf_exempt = getattr(self.handler, 'csrf_exempt', True)将补丁应用到您的活塞/resource.py 文件,如下所示:
self.handler = handler()
+ self.csrf_exempt = getattr(self.handler, 'csrf_exempt', True)
if not authentication:
self.authentication = NoAuthentication()
于 2011-08-21T18:46:26.283 回答
0
为什么你需要这样做?CSRF 是一个简单的域检查......但如果你真的需要它,答案在文档中:https ://docs.djangoproject.com/en/dev/ref/contrib/csrf/#csrf-protection-should -被禁用只为几个视图
于 2011-08-21T10:38:14.470 回答