如何使用Flask中的url_for
引用文件夾中的文件?例如,我在static
文件夾中有一些靜態文件,其中一些文件可能位於子文件夾中,如static/bootstrap
。使用url_for鏈接到Flask靜態文件
當我嘗試從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?