zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Blender基础操作
    反汇编及linux下edb的下载
    混淆矩阵(confusion_matrix)含义
    Python大数据第三次的作业
    Python的DataFrame基础使用
    Python数据标准化
    爬虫之xpath
    luffy项目上线
    爬虫之selenium
    celery
  • 原文地址:https://www.cnblogs.com/wujf/p/9298279.html
Copyright © 2011-2022 走看看