标签:打开 lazy method turn png api bsp pre web
Flask是一个基于Python开发的微型web框架
使用Flask实现简单的restful api
安装
pip install flask
eg:
from flask import Flask app = Flask(__name__) @app.route(‘/‘) def hello(): return ‘hello,world‘ if __name__ == "__main__": app.run()
浏览器打开http://127.0.0.1:5000/
页面输出
hello,world
GET方法
from flask import Flask,request,abort app = Flask(__name__) @app.route(‘/‘) def hello(): return ‘hello,world‘ @app.route("/testGet", methods=[‘GET‘]) def testGet(): name = request.args.get(‘name‘,‘‘) age = request.args.get(‘age‘,‘‘) return {‘name‘:name,‘age‘:age} if __name__ == "__main__": app.run()
postman测试
POST方法
from flask import Flask,request,abort app = Flask(__name__) @app.route(‘/‘) def hello(): return ‘hello,world‘ @app.route("/testPost", methods=[‘POST‘]) def testPost(): if not request.json or not ‘text‘ in request.json: abort(400) text = request.json.get(‘text‘, ‘‘) return {‘text‘:text} if __name__ == "__main__": app.run()
postman测试
标签:打开 lazy method turn png api bsp pre web
原文地址:https://www.cnblogs.com/baby123/p/14023538.html