结构

用户模块

  1. from flask import Blueprint
  2. bp = Blueprint("user", __name__, url_prefix="/user") # url_prefix 用于设置前缀
  3. @bp.route("/login") # 前缀 + login : hostname:5000/user/login
  4. def user_login():
  5. pass

数据模块

  1. from flask import Blueprint
  2. bp = Blueprint("book", __name__, url_prefix="/book")
  3. @bp.route("/book")
  4. def user_login():
  5. pass

结构和import

  1. from flask import Flask, render_template
  2. from apps.book import bp as book_bp
  3. from apps.user import bp as user_bp
  4. app = Flask(__name__)
  5. app.register_blueprint(book_bp)
  6. app.register_blueprint(user_bp)

在模块试图中渲染还是会从template中进行渲染
例如模板文件和静态文件都从默认路径中进行渲染。