Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.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
带Swagger的Python Flask Rest API-如何发布自定义模型_Python_Flask_Flask Restful - Fatal编程技术网

带Swagger的Python Flask Rest API-如何发布自定义模型

带Swagger的Python Flask Rest API-如何发布自定义模型,python,flask,flask-restful,Python,Flask,Flask Restful,我正试图用Swagger构建一个FlaskRESTAPI,它接受2个输入参数(BodyTemperature和CoughSeverity),并生成一个输出JSON 如果我通过URL提供这两个参数,代码运行良好。我的代码看起来像这样 from flask import Flask from flask_restplus import Resource, Api, fields app = Flask(__name__) api = Api(app = app, version = "1

我正试图用Swagger构建一个FlaskRESTAPI,它接受2个输入参数(BodyTemperature和CoughSeverity),并生成一个输出JSON

如果我通过URL提供这两个参数,代码运行良好。我的代码看起来像这样

from flask import Flask
from flask_restplus import Resource, Api, fields

app = Flask(__name__)
api = Api(app = app, version = "1.0", title = "Patient Predictor", 
description = "Takes patiens symptoms as input and provides a estimated health condition of the patient")

name_space = api.namespace('PatientCondition', description='Get patient condition by symptoms')

@name_space.route("/GetPatientCondition/<float:BodyTemp>/<int:CoughSeverity>")

class PatientCondition(Resource):

def post(self, BodyTemp, CoughSeverity):
    
    return {
        "status": "Success",
        "PatientCondition": "Patient temp is " + str(BodyTemp),
        "CoughSeverity": "Patient cough severity is " + str(CoughSeverity)
    }

if __name__ == '__main__':
    app.run()
但是我不知道如何在POST方法中使用这个模型,这样我就可以在swagger UI中通过JSON输入模型。任何帮助都将是非常感激的

PatientSymptomModel = api.model('PatientSymptom', 
      {
          'BodyTemp': fields.Float(required = True, description="Body Temparature of the person"),
          'CoughSeverity': fields.Float(required = True, description="Cough Severity of the person")
      }
    )