标签:相同 自动 ref 实现 bsp flask int new 文件的
蓝图内置扩展(实现的是路由的拆分)
1 ‘‘‘----------- app.py -------------‘‘‘ 2 from flask import Flask 3 from users_views import blue1 4 from orders_views import blue2 5 6 app = Flask(__name__) 7 8 # 路由注册 9 app.register_blueprint(blueprint=blue1) 10 app.register_blueprint(blueprint=blue2) 11 12 13 if __name__ == ‘__main__‘: 14 app.run()
1 ‘‘‘ ------------ users_views.py ---------------‘‘‘ 2 from flask import Blueprint 3 # blue1 的设置(名字,导入的名字,前缀名称) 4 blue1 = Blueprint("blue1",__name__, url_prefix="/users") 5 6 # 用blue1设置路由,用前缀名字区分相同名字的路由:http://127.0.0.1:5000/users/ 7 @blue1.route("/") 8 def index(): 9 return "用户的 Blue 信息" 10 11 12 @blue1.route("/user/") 13 def home(): 14 return "用户信息"
1 ‘‘‘ ----------- orders_vieews.py ----------‘‘‘ 2 from flask import Blueprint 3 # blue2 的设置(名字,导入的名字,前缀名称) 4 blue2 = Blueprint("blue2", __name__, url_prefix="/orders") 5 6 # 用blue2设置路由,用前缀名字区分相同名字的路由:http://127.0.0.1:5000/orders/ 7 @blue2.route("/") 8 def haha(): 9 return "订单的 blue2 信息" 10 11 12 @blue2.route("/orders/") 13 def ppp(): 14 return "订单信息"
静态文件路径
1 from flask import Flask 2 from users_views import blue1 3 from orders_views import blue2 4 # 静态文件路径配置。static_folder=‘news/static‘ 是配置新的静态文件的路径 5 app = Flask(__name__,static_folder=‘news/static‘) 6 7 # 路由注册 8 app.register_blueprint(blueprint=blue1) 9 app.register_blueprint(blueprint=blue2)
终端输入插件扩展:flask-script
1 from flask import Flask 2 from flask_script import Manager 3 4 app = Flask(__name__) 5 # 配置flask-script 6 manager = Manager(app=app) 7 8 @app.route(‘/‘) 9 def hello_world(): 10 return ‘Hello World!‘ 11 12 # 使用flask-script 13 if __name__ == ‘__main__‘: 14 manager.run()
标签:相同 自动 ref 实现 bsp flask int new 文件的
原文地址:https://www.cnblogs.com/TMMM/p/11478808.html