zoukankan      html  css  js  c++  java
  • 自动生成接口文档

    # 1 安装
    pip install coreapi
    
    # 2 在路由中配置
        from rest_framework.documentation import include_docs_urls
    
        urlpatterns = [
            ...
            path('docs/', include_docs_urls(title='站点页面标题'))
        ]
        
    # 3 视图类:自动接口文档能生成的是继承自APIView及其子类的视图。
        -1) 单一方法的视图,可直接使用类视图的文档字符串,如
            class BookListView(generics.ListAPIView):
                """
                返回所有图书信息.
                """
                
        -2)包含多个方法的视图,在类视图的文档字符串中,分开方法定义,如
            class BookListCreateView(generics.ListCreateAPIView):
                """
                get:
                返回所有图书信息.
                post:
                新建图书.
                """
                
        -3)对于视图集ViewSet,仍在类视图的文档字符串中封开定义,但是应使用action名称区分,如
            class BookInfoViewSet(mixins.ListModelMixin, mixins.RetrieveModelMixin, GenericViewSet):
                """
                list:
                返回图书列表数据
                retrieve:
                返回图书详情数据
                latest:
                返回最新的图书数据
                read:
                修改图书的阅读量
                """
  • 相关阅读:
    A Famous City
    A Famous ICPC Team
    配置单元测试环境,找不到SenTestingKit
    linux解压.tar命令
    语音输入——科大讯飞
    查看dsym错误信息
    工程里关闭arc
    导入签名错误
    mac显示隐藏文件
    类uialertview弹出动画
  • 原文地址:https://www.cnblogs.com/ZhZhang12138/p/14875910.html
Copyright © 2011-2022 走看看