关于django:ContentType-header-is-texthtml-not-applicationjson

14次阅读

共计 665 个字符,预计需要花费 2 分钟才能阅读完成。

报错
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 文件中增加路由配置

正文完
 0