• 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!'

    有追求,才有动力!

    向每一个软件工程师致敬!

    by wujf

    mail:921252375@qq.com

  • 相关阅读:
    云南网页首页布局全代码
    表格样式(鼠标经过时整行变色)
    做自定义圆角矩形
    网页布局
    黄冈中学首页的模板简图
    动态网页简版
    十字绣首页设计
    go组合
    http rpc关联
    php echo print
  • 原文地址:https://www.cnblogs.com/wujf/p/9298279.html
Copyright © 2020-2023  润新知