drf中自动生成api文档

一、安装模块:pip install coreapi。

二、路由中配置:

  1、导入模块:rest_framework.documentation.include_docs_urls。

  2、url:

    urlpatterns = [
        ...
        path('docs/', include_docs_urls(title='文档站点页面标题'))
    ]

三、视图类中书写接口文档相关信息:

  1、只有单一方法的视图类:

        class TarListView(ListAPIView):
            """
            返回所有xxx(会自动对应list方法)
            """

  2、包含多个方法的视图类:

        class TarListCreateView(ModelViewSet):
            """
            get:
            返回所有xxx
            post:
            新增一个或多个xxx
            ...
            """
原文地址:https://www.cnblogs.com/caoyu080202201/p/13299565.html