赞
踩
参考文档:https://blog.csdn.net/qq_38648652/article/details/103833707
from flask import Flask from goods import app_goods #循环引用,解决方法,推迟一方的导入,让例外一方完成 app = Flask(__name__) #注册蓝图(注册goods模块下的蓝图对象,就可以访问相应的路径) app.register_blueprint(app_goods) @app.route('/') def index(): return "index page" if __name__ == '__main__': print(app.url_map) app.run(host='0.0.0.0', debug=True)
# from main import app
from flask import Blueprint
#创建一个蓝图的对象,蓝图是一个小模块抽象的概念
app_goods = Blueprint("app_goods", __name__)
@app_goods.route('/goods', methods=['GET', 'POST'])
def goods():
return 'goods page'
@app_goods.route('/hu')
def hu():
return 'hu page'
app.register_blueprint(app_goods, url_prefix="/goods_route")
from flask import Flask from goods import app_goods from cart import app_cart #循环引用,解决方法,推迟一方的导入,让例外一方完成 app = Flask(__name__) #注册蓝图(注册goods模块下的蓝图对象,就可以访问相应的路径) app.register_blueprint(app_goods, url_prefix="/goods_route") app.register_blueprint(app_cart, url_prefix="/cart") @app.route('/') def index(): return "index page" if __name__ == '__main__': print(app.url_map) app.run(host='0.0.0.0', debug=True)
from flask import Blueprint
app_cart = Blueprint("app_cart", __name__, template_folder="templates")
#在__init__.py文件被执行的时候,把视图加载进来,让蓝图与应用程序知道有视图的存在
from .views import hu
from . import app_cart
@app_cart.route('/hu1')
def hu():
return render_template("cart.html")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。