链接到带有url_for的烧瓶静态文件你怎么用url_for在容器中引用文件夹中的文件?例如,我在static文件夹,其中一些文件夹可能位于子文件夹中,如static/bootstrap.当我试图从static/bootstrap我犯了个错误。 <link rel=stylesheet type=text/css href="{{ url_for('static/bootstrap', filename='bootstrap.min.css') }}">我可以引用不在子文件夹中的文件,这是可行的。 <link rel=stylesheet type=text/css href="{{ url_for('static', filename='bootstrap.min.css') }}">引用静态文件的正确方法是什么?url_for?我该如何使用url_for在任何级别上为静态文件生成URL?
2 回答
![?](http://img1.sycdn.imooc.com/54584eff000195a302200220-100-100.jpg)
慕虎7371278
TA贡献1802条经验 获得超4个赞
static
Flask
static_url_path
static_folder
static_folder
static_url_path
filename
static_folder
static_url_default
:
url_for('static', filename='path/to/file')
static_folder/path/to/file
static_url_default/path/to/file
.
static/bootstrap
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='bootstrap/bootstrap.min.css') }}">
<link rel="stylesheet" type="text/css" href="static/bootstrap/bootstrap.min.css">
url_for
![?](http://img1.sycdn.imooc.com/545845b40001de9902200220-100-100.jpg)
偶然的你
TA贡献1841条经验 获得超3个赞
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { try_files $uri =404; }
添加回答
举报
0/150
提交
取消