我有一个包含模板和静态文件的Flask蓝图.模板正确呈现,但链接的CSS文件返回404未找到.如何提供位于蓝图文件夹下的静态文件?
app/
__init__.py
auth/
__init__.py
static/
style.css
templates/
index.html
Run Code Online (Sandbox Code Playgroud)
auth = Blueprint('auth', __name__, template_folder='templates')
@auth.route('/')
def index():
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
Run Code Online (Sandbox Code Playgroud)
通过传递告诉蓝图其静态文件夹的位置static_folder
,然后用于url_for
生成static
蓝图上的路径的URL .这在文档中描述.
auth = Blueprint('auth', __name__, template_folder='templates', static_folder='static')
Run Code Online (Sandbox Code Playgroud)
url_for('auth.static', filename='style.css')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1193 次 |
最近记录: |