flask搭建
Posted wujf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flask搭建相关的知识,希望对你有一定的参考价值。
1、定义路由app.py
from flask import Flask, request from flask import Blueprint app = Flask(__name__) test = Blueprint(‘test‘, __name__) @app.before_request def before_request(): print("before_request") print(request) @app.after_request def after_request(param): print("after_request") print(param.data) # resp =app.make_response(‘after‘) return param @app.teardown_request def teardown_request(ex): print("teardown_request")
2、定义main入口main.py
from app import app from app import test import testController from flask import Flask, request if __name__ == ‘__main__‘: # 通过蓝图实现请求上下文 app.register_blueprint(test, url_prefix=‘/test‘) # 默认监听端口是5000 # 一定要指定debug=False不然断点不命中 app.run(host=‘0.0.0.0‘, port=888, debug=False)
3、定义控制器testController.py
from app import app from app import test @app.route(‘/hello‘, methods=[‘POST‘]) def hello(): return ‘hello app!‘ @test.route(‘/hello‘, methods=[‘POST‘]) def hello(): return ‘hello test!‘
以上是关于flask搭建的主要内容,如果未能解决你的问题,请参考以下文章