结构
用户模块
from flask import Blueprint
bp = Blueprint("user", __name__, url_prefix="/user") # url_prefix 用于设置前缀
@bp.route("/login") # 前缀 + login : hostname:5000/user/login
def user_login():
pass
数据模块
from flask import Blueprint
bp = Blueprint("book", __name__, url_prefix="/book")
@bp.route("/book")
def user_login():
pass
结构和import
from flask import Flask, render_template
from apps.book import bp as book_bp
from apps.user import bp as user_bp
app = Flask(__name__)
app.register_blueprint(book_bp)
app.register_blueprint(user_bp)
在模块试图中渲染还是会从template中进行渲染
例如模板文件和静态文件都从默认路径中进行渲染。