Content-Type header is "text/html", not "application/json"
Posted ponponon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Content-Type header is "text/html", not "application/json"相关的知识,希望对你有一定的参考价值。
报错
DRF运行报错 ValueError: Content-Type header is "text/html", not "application/json"
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\\Users\\17293\\Desktop\\Coder\\Python\\Django\\twitter\\newsfeeds\\api\\tests.py", line 41, in test_list
print(response.json())
File "C:\\Users\\17293\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\django\\test\\client.py", line 662, in _parse_json
raise ValueError(
ValueError: Content-Type header is "text/html", not "application/json"
----------------------------------------------------------------------
Ran 1 test in 0.362s
FAILED (errors=1)
Destroying test database for alias \'default\'...
报错原因和解决办法:
去 urls.py
文件中添加路由配置
以上是关于Content-Type header is "text/html", not "application/json"的主要内容,如果未能解决你的问题,请参考以下文章
Request header field Content-Type is not allowed by Access-Control-Allow-Headers
angularjs post Request header field Content-Type is not allowed by Access-Control-Allow-Headers in p
axios.post请求出错:Request header field content-type is not allowed by Access-Control-Allow-Headers in……
axios跨域请求报错:Request header field content-type is not allowed by Access-Control-Allow-Headers in pref
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported&qu
.Net HttpClient Headers.Add("Content-Type", "application/json") 异常