zoukankan      html  css  js  c++  java
  • DRF 接口文档添加请求参数描述

    DRF 接口文档添加请求参数描述

    安装django-rest-framework,编写视图函数之后,发现生成的接口文档没有请求参数,如下

    解决方案

    from rest_framework.views import Response, APIView
    import coreschema  # 导入
    from rest_framework.schemas import ManualSchema  # 导入
    import coreapi  # 导入
    class User(APIView):
        # 编写以下内容
        schema = ManualSchema(fields=[    
            coreapi.Field(
                "first_field",
                required=True,
                location="path",
                schema=coreschema.String(),
                description="hello world"
            ),
            coreapi.Field(
                "second_field",
                required=False,
                location="path",
                schema=coreschema.String(),
                description=" name"
            ),
        ])
        def get(self, request):
            """
                get:
               获取用户信息.
            """
            return Response({"status": True, "method": request.method, "data": ""})
    
    

    结果

    新的问题

    原本的接口描述不见了,先这样,后续解决

  • 相关阅读:
    vue $emit的使用
    flask config 环境变量配置
    get请求
    下载及安装
    测试用例写作
    系统测试
    测试方法
    软件质量
    测试基础
    子网掩码
  • 原文地址:https://www.cnblogs.com/jruing/p/14658157.html
Copyright © 2011-2022 走看看