Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Flasger YAML用于后JSON API_Python_Api_Post_Flask_Swagger - Fatal编程技术网

Python Flasger YAML用于后JSON API

Python Flasger YAML用于后JSON API,python,api,post,flask,swagger,Python,Api,Post,Flask,Swagger,在这篇文章之后: 我能够编写一个简单的API,在这里我发布了一个json对象(一个名字&姓氏&一个generate ID),将其插入数据库 在那之后,我想用招摇过市的人来为它建模。 它已经在为get或get_by_id工作,但该帖子不可能工作 在我的python代码中,我有以下内容: from flask import Flask, jsonify, request @app.route('/api/v1/list', methods=['POST']) @swag_from('index_p

在这篇文章之后:

我能够编写一个简单的API,在这里我发布了一个json对象(一个名字&姓氏&一个generate ID),将其插入数据库

在那之后,我想用招摇过市的人来为它建模。 它已经在为get或get_by_id工作,但该帖子不可能工作

在我的python代码中,我有以下内容:

from flask import Flask, jsonify, request
@app.route('/api/v1/list', methods=['POST'])
@swag_from('index_post.yml')
def add_entry():
    request_json = request.get_json()
    value1 = request_json.get('First_Name')
    value2 = request_json.get('Last_Name')
    if value1 is not None and value2 is not None:
        cursor.execute("INSERT INTO person (first_name,last_name) VALUES 
        (%s,%s)", (value1, value2))
    data = conn.commit()
    return jsonify(data)
在YAML文件中,我有:

paths:
/api/v1/list:
post:
description: testpost
operationId: PostNewName
consumes:
  - application/json
parameters:
  - name: body
    in: body
    required: true
    schema:
      id : toto
      required:
        - first
        - last
      properties:
        first:
          type: string
          description: Unique identifier representing a First Name
        last:
          type: string
          description: Unique identifier representing a Last Name
responses:
  200:
    description: creation OK
但是这些参数不会出现在招摇过市的html页面上。 我不知道这是什么问题


感谢您的帮助。

放置操作id:添加或删除标记操作id

如果缩进错误,您可以在处编辑和验证您的架构。我开始修好它,但我想你现在应该可以做剩下的事情了:

swagger: '2.0'
info:
  title: Demo App
  version: "1"
paths:
  /api/v1/list:
    post:
      description: testpost
      operationId: PostNewName
      consumes:
        - application/json
      parameters:
        - name: body
          in: body
          required: true
          schema:
            id : toto
            required:
              - first
              - last
            properties:
              first:
                type: string
                description: Unique identifier representing a First Name
              last:
                type: string
                description: Unique identifier representing a Last Name
      responses:
        200:
          description: creation OK

当你说“发布不可能”时,你的意思是“大摇大摆”用户界面没有加载或无法发布数据?