django:通用类视图 + POST = HTTP 405(不允许的方法)
最近我开始将一些视图函数转换为通用视图。 转换预期处理 POST 请求(通过 AJAX 形式)的函数会导致“405 Method not allowed”HTTP 异常。 我确信与 CSRF 无关:Ajax 发送有效令牌,将通用视图更改回视图函数(在测试用例中,它们本质上是相同的)解决了问题,并且 - 最后 -出于测试目的,我禁用了 CSRF 中间件。 有人遇到过类似的问题吗?
Recently I've started converting some of the view functions to Generic Views.
Converting the function which was expected to handle POST request (via AJAX form) results in "405 Method not allowed" HTTP exception.
I'm sure is not about CSRF: Ajax sends valid token, changing the generic view back to view function (in the test case, they're essentially the same) fixes the problem, and - lastly - for testing purposes, I've disabled CSRF middleware.
Did anyone experienced similar problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您正在使用基于类的视图。如果是这样,那么您需要在视图中定义
post
方法或使用 mixin 来执行此操作(例如django.views.generic.edit.ProcessFormView
)。如果您想完全理解为什么这是必要的,请查看
方法。django.views.generic.base.View
的调度I suppose you are using class-based views. If so then you need to define
post
method in your view or use mixin which does it (django.views.generic.edit.ProcessFormView
for example). If you want to fully understand why this is necessary then look atdispatch
method ofdjango.views.generic.base.View
.