zoukankan      html  css  js  c++  java
  • flask 蓝图简单格式(一)

    使用蓝图的方便之处就是 将不同的地址分离,不至于臃肿,便于后续功能扩展

    manage.py

     1 from apps.test1  import test1 #地址一
     2 from apps.test2  import test2 #地址二
     3 
     4 app = Flask(__name__)
     5 app.register_blueprint(test1) 
     6 app.register_blueprint(test2) 
     7 
     8 
     9 @app.route('/index')
    10 def index():
    11     return render_template("index.html")
    12 
    13 @app.errorhandler(404)
    14 def not_found(e):
    15     return render_template("404.html")
    16 
    17 if __name__ == '__main__':
    18     app.run(host='0.0.0.0',port=5000,debug=true)
    View Code

    apps.test1

    from flask import Blueprint, render_template
    
    test1= Blueprint('test1', __name__)
    
    @test1.route('/xxxxx',methods=['GET','POST'])
    def xxxx():
        return '11'
    
    `
    `
    `
    `
    `
    View Code

    apps.test2 

     1 from flask import Blueprint, render_template
     2 
     3 test2= Blueprint('test2', __name__)
     4 
     5 @test2.route('/xxxxx',methods=['GET','POST'])
     6 def xxxx():
     7     return '11'
     8 
     9 `
    10 `
    11 `
    12 `
    13 `
    View Code

    注:

    此种格式没有用到 前缀,访问 直接访问,不需要加 test1 、test2  

    如果需要访问需要前缀,可以使用  

    1 app.register_blueprint(test1, url_prefix='/test1')
    url_prefix
  • 相关阅读:
    ugui点击穿透判断
    c#字符串代码,动态创建编译器
    github项目分享
    unity 2d 版的lookAt
    unity全屏截图
    shader例子
    AcWing 329. 围栏障碍训练场
    AcWing 326. XOR和路径
    AcWing 324. 贿赂FIPA
    AcWing 322. 消木块
  • 原文地址:https://www.cnblogs.com/whycai/p/12650459.html
Copyright © 2011-2022 走看看