【发布时间】:2014-09-11 19:56:03
【问题描述】:
我在我的 Flask 应用程序中设置了一个蓝图,但我似乎无法让我的静态文件夹工作。当它尝试访问它们时,我不断收到 404 错误:
127.0.0.1 - - [11/Sep/2014 15:14:20] "GET /static/js/bootstrap.min.js HTTP/1.1" 404 -
127.0.0.1 - - [11/Sep/2014 15:14:20] "GET /static/static/css/bootstrap.min.css HTTP/1.1" 404 -
css 也附加了两次静态。 JS 具有正确的 /static 但似乎不起作用。现在,我的静态文件夹位于蓝图根路径 (app/dashboard) 中。我尝试将其放入 app/static,但我得到了完全相同的错误。
我有以下设置:
app/dashboard/__init__.py:
from flask import Blueprint
dashboard = Blueprint('dashboard', __name__, template_folder='templates', static_folder='static')
from application.dashboard import controllers
app/__init__.py:
# Blueprints
from flask import Blueprint
from application.dashboard import dashboard
app.register_blueprint(dashboard)
在app/templates/layout.html 中,我有一行引用了两个静态文件,如下所示:
<link rel="stylesheet" type="text/css" href="{{ url_for('dashboard.static', filename='css/bootstrap.min.css') }}">
<script src="{{ url_for('dashboard.static', filename='js/bootstrap.min.js') }}"></script>
我的app/dashboard/static 目录:
$ tree application/dashboard/static/
application/dashboard/static/
├── css
│ ├── bootstrap-theme.css
│ ├── bootstrap-theme.css.map
│ ├── bootstrap-theme.min.css
│ ├── bootstrap.css
│ ├── bootstrap.css.map
│ └── bootstrap.min.css
├── fonts
│ ├── glyphicons-halflings-regular.eot
│ ├── glyphicons-halflings-regular.svg
│ ├── glyphicons-halflings-regular.ttf
│ └── glyphicons-halflings-regular.woff
└── js
├── bootstrap.js
└── bootstrap.min.js
知道这里发生了什么吗?如何正确构建我的蓝图?我已按照 Flask 文档中的说明进行操作,但出现此错误。
谢谢。
【问题讨论】: