flask 项目中蓝本的使用(flask 43)

2019-08-13 14:45:48 浏览数 (1)

views目录下 admin.py auth.py blog.py

from flask import Blueprint admin_bp=Blueprint('admin',name)

from flask import Blueprint auth_bp=Blueprint('auth',name)

@auth_bp.route("/login") def login(): pass @auth_bp.route("/logout") def logout(): pass

from flask import Blueprint blog_bp=Blueprint('blog',name)

app.py

from flask import Flask from views.admin import admin_bp from views.auth import auth_bp from views.blog import blog_bp

import os app = Flask(name) basedir = os.path.abspath(os.path.dirname(os.path.dirname(file)))

def register_blueprints(app): app.register_blueprint(blog_bp) app.register_blueprint(admin_bp) app.register_blueprint(auth_bp)

蓝本指定静态资源的用法:

auth_bp=Blueprint('auth',name,static_folder='static',static_url_path='/auth/static',template_folder='templates') url_for('auth.static',filename='style.css')

0 人点赞