我有一个定义为的蓝图:
auth_login = Blueprint('auth_login', __name__, template_folder='templates', static_folder='static', static_url_path='/static')
我将其注册为:
app.register_blueprint(auth_login, url_prefix='/user')
我有一条路线:
@auth_login.route('/<username>/')
def profile(username):
return render_template('profile/user.html',
username = username)
使用此设置,/ user /端点永远不会像我得到的那样加载静态文件,
“ GET /user//static/css/lib/bootstrap.min.css HTTP / 1.1” 404-“ GET /user//static/css/lib/font-awesome/css/font-awesome.min.css HTTP / 1.1“ 404-
我真正想要的是查看根应用程序的静态文件夹而不是蓝图,因此我希望它请求
“ GET /static/css/lib/bootstrap.min.css HTTP / 1.1” 200-
是否可以通过static_folder或static_url_path进行配置,以便路由将在根目录而不是相对于安装蓝图的位置查找静态文件?
默认情况下,Flask将/static
URL设置为不提供文件服务{application_root}/static
-您正在用蓝图的代码覆盖默认值。(URL仍然/static
是{application_root}/path/to/blueprint/static
,但文件夹是,从实际情况来看,这不是您想要的)。
只需删除初始化的static_folder
和static_url
参数,Blueprint
URL应该就可以正常工作(假设{application_root}/static
文件夹中有适当的CSS 。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句