如何用flask_restplus显示模式示例?

2024-05-29 06:24:55 发布

您现在位置:Python中文网/ 问答频道 /正文

[用Python,烧瓶,烧瓶,大摇大摆]

我试图用flask_restplusschema model显示为下图。 在yml而不是python中使用原型模式:

enter image description here

我创建了schema_model,但我不确定如何将其输入到代码中,以便它与GET调用配对。如何显示schema_模型?在


import requests
from flask import Flask, request, json, jsonify, Blueprint
from flask_restplus import Resource, Api, reqparse, fields, SchemaModel

app = Flask(__name__)
api = Api(app, title='Function Test', doc='/FT')

rbt = api.namespace('RBT', description='Accessible by API')

address = api.schema_model('Address', {
    'properties': {
        'road': {
            'type': 'string'
        },
    },
    'type': 'object'
})

@rbt.route('/<string:resource>/<string:responder>/<string:tag>')
class RBT(Resource):

    @rbt.doc(responses={
        200: 'Success',
        400: 'Validation Error',
        500: 'Internal Server Error'
    })

    #@rbt.marshal_with(address)
    def get(self, resource, responder, tag, **kwargs):
        '''TC#1 Definition'''
        url2 = 'http://' + host +  port + '/' + resource + '?' +responder
        print(url2)

        url = 'http://httpbin.org/get'

        parameters = {'resource': resource, 'responder':responder, 'tag': tag}
        r = requests.get(url)
        data = r.text

        return data

Tags: importrestapiflaskgetstringmodel烧瓶

热门问题