鏈接到帶有url_for的燒瓶靜態(tài)文件你怎么用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') }}">引用靜態(tài)文件的正確方法是什么?url_for?我該如何使用url_for在任何級別上為靜態(tài)文件生成URL?
2 回答

慕虎7371278
TA貢獻1802條經(jīng)驗 獲得超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

偶然的你
TA貢獻1841條經(jīng)驗 獲得超3個贊
location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { try_files $uri =404; }
添加回答
舉報
0/150
提交
取消