如何使用Flask-RESTful


1、在Flask中编写接口需要使用Flask-RESTful模块

2、使用PyCharm安装Flask-RESTful模块

3、使用Flask-RESTful编写接口

from flask import Flask, render_template
from flask_restful import Api, Resource

app = Flask(__name__)
api = Api(app)

class TestView(Resource):
    def get(self):
        return {'username': 'zhangsan'}

api.add_resource(TestView, '/test/')

@app.route('/')
def index():
    return render_template('index.html')

if __name__ == '__main__':
    app.run()

results matching ""

    No results matching ""