Django / DRF - 405 DELETE操作不允许使用方法 [英] Django/DRF - 405 Method not allowed on DELETE operation

查看:4658
本文介绍了Django / DRF - 405 DELETE操作不允许使用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地计算机(node& django's)上使用两个开发服务器。

I'm working with two dev servers on my local machine (node & django's).

我已经添加了 django-cors-headers ,以允许所有来源&方法(开发者)使用以下设置:

I've added django-cors-headers to the project to allow all origins & methods (on dev) with the following settings :

CORS_ORIGIN_ALLOW_ALL = 'ALL'
CORS_ALLOW_METHODS = (
        'GET',
        'POST',
        'PUT',
        'PATCH',
        'DELETE',
        'OPTIONS'
    )

尝试删除时我得到405。
查看响应头

I'm getting 405 when attempting DELETE. Looking at the response headers

HTTP/1.0 405 METHOD NOT ALLOWED
Date: Mon, 03 Nov 2014 10:04:43 GMT
Server: WSGIServer/0.1 Python/2.7.5
Vary: Cookie
X-Frame-Options: SAMEORIGIN
Content-Type: application/json
Access-Control-Allow-Origin: *
Allow: GET, POST, HEAD, OPTIONS

注意 DELETE & PATCH / PUT 不存在于允许的方法列表中。

Notice that DELETE & PATCH / PUT are not present in the allowed methods list.

我的配置中是否缺少某些内容?

Is there something missing from my configuration ?

推荐答案

响应与列表视图非常相似 ( / api / resource / )。列表视图只支持 GET 列出所有对象, POST 创建一个新对象。

The response looks very similar to that of the list view (/api/resource/) for a ViewSet. List views only support GET, to list all of the objects, and POST to create a new object.

DELETE 请求只能在详细视图 / api / resource / 1 / )。这是因为Django REST Framework需要知道您要删除的对象,并且无法仅从列表视图检索此信息。

DELETE requests are only allowed on the detail view (/api/resource/1/). This is because Django REST Framework needs to know what object you are looking to delete, and this information cannot be retrieved from just the list view.

这篇关于Django / DRF - 405 DELETE操作不允许使用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆