如何使用flask-ReSTplus记录桩身? [英] How to document the post body using flask-ReSTplus?

查看:141
本文介绍了如何使用flask-ReSTplus记录桩身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何记录要在value字段中显示的输入正文,以便用户知道要张贴什么内容?当前使用以下数据:

How to document the input body that is expected to be posted in the value field to appear so that the user knows what to post? the following data is used currently:

{
 "customer_id": "",
 "service_id": "",
 "customer_name": "",
 "site_name": "",
 "service_type": ""
}

默认情况下,我们可以使用上面的json填充值吗?

can we populate the value by default with the above json?

代码:

post_parser = reqparse.RequestParser()
post_parser.add_argument('database',  type=list, help='user data', location='json')

@ns_database.route('/insert_user')
class database(Resource):
@ns_database.expect(post_parser)
def post(self):
    """insert data"""
    json_data = request.json
    customer_id = json_data['customer_id']
    service_id = json_data['service_id']
    customer_name = json_data['customer_name']
    site_name = json_data['site_name']
    service_type = json_data['service_type']

推荐答案

我已经使用以下模型(部分)解决了它

I have solved it (partially) using the following model

""" Model for documenting the API"""

insert_user_data = ns_database.model("Insert_user_data",
                                 {
                                     "customer_id": 
fields.String(description="cust ID", required=True),
                                     "service_id": 
fields.String(description="service ID", required=True),
                                     "customer_name": 
fields.String(description="Customer1", required=True),
                                     "site_name": 
fields.String(description="site", required=True),
                                     "service_type": 
fields.String(description="service", required=True)
                                 }
                                 )


@ns_database.route('/insert_user')
class database(Resource):
    @ns_database.expect(insert_user_data)
    def post(self):
        """insert data"""
        json_data = request.json
        customer_id = json_data['customer_id']
        service_id = json_data['service_id']
        customer_name = json_data['customer_name']
        site_name = json_data['site_name']
        service_type = json_data['service_type']

现在API显示了用于数据输入的模型和示例

now the API shows model for data input and an example

这篇关于如何使用flask-ReSTplus记录桩身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆