如何使用 flask-ReSTplus 记录 post body?
How to document the post body using flask-ReSTplus?
如何记录预期 post 将在 value
字段中显示的输入 body,以便用户知道要 post 什么?当前使用以下数据:
{
"customer_id": "",
"service_id": "",
"customer_name": "",
"site_name": "",
"service_type": ""
}
我们可以用上面的 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']
假设您正在使用 Flask 模板 return /database/insert_user
网页,您可以简单地使包含数据库信息(customer_id 等)的变量可访问 [=12] =] 被调用,然后将变量传递给它。
例如,如果您想传递 customer_id 变量:
return render_template("insert_user.html",
x=customer_id)
假设 insert_user.html
是您的模板文件,然后您可以使用 {{ x }}
将数据放在任何您想要的地方
我已经使用以下模型(部分)解决了它
""" 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 显示数据输入模型和示例
如何记录预期 post 将在 value
字段中显示的输入 body,以便用户知道要 post 什么?当前使用以下数据:
{
"customer_id": "",
"service_id": "",
"customer_name": "",
"site_name": "",
"service_type": ""
}
我们可以用上面的 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']
假设您正在使用 Flask 模板 return /database/insert_user
网页,您可以简单地使包含数据库信息(customer_id 等)的变量可访问 [=12] =] 被调用,然后将变量传递给它。
例如,如果您想传递 customer_id 变量:
return render_template("insert_user.html",
x=customer_id)
假设 insert_user.html
是您的模板文件,然后您可以使用 {{ x }}
我已经使用以下模型(部分)解决了它
""" 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 显示数据输入模型和示例