且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Django Rest框架中使用coreapi客户端?

更新时间:2022-06-22 00:46:38

我遇到了相同的错误-python 3.8.5,Django 3.1,DRF 3.12.1.对我来说,相似之处在于 coreapi 返回的是 DownloadedFile 而不是 Document ,这似乎是在 coreapi 收到时发生的一种意想不到的内容类型.

I hit the same error -- python 3.8.5, Django 3.1, DRF 3.12.1. The similarity for me was that coreapi returns a DownloadedFile instead of a Document, which seems to happen when coreapi receives a content-type that it doesn't expect.

对我来说,解决方案是:

For me, solution was:

  1. pip install openapi-codec (如果尚未安装)
  2. coreapi获取http://localhost:8000/openapi?format = openapi-json --format = openapi
  1. pip install openapi-codec (if you haven't installed it yet)
  2. coreapi get http://localhost:8000/openapi?format=openapi-json --format=openapi

您会知道它成功了,因为您将看不到 DownloadedFile 的任何提法,而是所有可用标签/操作的摘要.

You'll know it succeeded because you won't see any mention of DownloadedFile, instead a summary of the available tags/actions.

不确定为什么要强制使用格式.

Not sure why forcing the format should be necessary.