当我通过基本身份验证在邮递员中使用PUT方法时,出现错误,我正在处理Django rest-framework

时间:2019-10-01 15:57:33

标签: django postman

{
      "detail":"Unsupported media type \"text/plain\" in request."
}

this image is from postman

3 个答案:

答案 0 :(得分:1)

它的发生是由于您请求的内容类型。

  1. 首先检查您的视图内容类型。 2.根据邮递员的观点更改内容类型。

例如:

标题->添加 键:“内容类型” 值:“ application / json”

答案 1 :(得分:1)

在设置栏下方有一个“Content-Type”选项,尝试将其更改为 JSONenter image description here

答案 2 :(得分:0)

def do(method ='get', data={}, is_json =True):
headers = {}
if is_json:
    headers['content-type'] ='application/json'
    data = json.dumps(data)
r = requests.request(method, ENDPOINT, data=data, headers = headers )
print(r.text)
print(r.status_code)
return r


do(method='post', data={"content": "some cool api ", 'user':1})