python - 在 Flask 中使用 bootstrap/css 模板时出现 HTTP 404 错误

标签 python html css flask

昨天刚开始学Flask,想做一个简单的单页网页。我复制了一个在网上找到的 Bootstrap 模板,但是当我运行我的主 python 程序时,我不断收到以下错误:

127.0.0.1 - - [26/May/2019 23:13:15] "GET / HTTP/1.1" 200 -

127.0.0.1 - - [26/May/2019 22:13:15] "GET /vendor/bootstrap.min.css HTTP/1.1" 404 -

127.0.0.1 - - [26/May/2019 22:13:15] "GET /vendor/jquery.min.js HTTP/1.1" 404 -

127.0.0.1 - - [26/May/2019 22:13:15] "GET /vendor/full-width-pics.css HTTP/1.1" 404 -

127.0.0.1 - - [26/May/2019 22:13:15] "GET /vendor/bootstrap.bundle.min.js HTTP/1.1" 404 -

这是我的根目录:

-FortniteStatBot.py

-Templates
| 
|----index.html
|
|----vendor
|
|---- All the other static files

我查看了有关堆栈溢出的其他帖子并尝试了人们建议的所有方法,但它并没有解决问题。我尝试过的一些事情是添加静态 url 路径/文件夹。还看到有人建议我删除目录路径中的尾随“/”,但这也没有解决问题。


app = Flask(__name__, static_url_path= '', static_folder= '/Templates/vendor')

app._static_folder = 'Templates/vendor'

我在我的 html 文件中试过这样的东西,但它也没有用:

<link href="{{ url_for('static', filename='/vendor/bootstrap.min.css/') }}" rel="stylesheet">

尽管尝试了多种不同的方法,但我仍然遇到相同的错误,所以我想知道是否有人知道如何修复此错误?

我在 .py 文件中的唯一函数中使用了这个返回值:

return render_template('index.html', stats = accountInfo, accountName = playerName)

最佳答案

您可能正在寻找与 static_folder 结合使用的 templates_folder。来自文档:

static_folder – the folder with static files that should be served at

template_folder – the folder that contains the templates that should be used by the application. Defaults to 'templates' folder in the root path of the application.

关于python - 在 Flask 中使用 bootstrap/css 模板时出现 HTTP 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56331083/

相关文章:

python - 在 Python 中切掉列表中每个(列表)元素中的第一个元素

html - Bootstrap 4 navbar-toggler 位置随定义的高度变化?

站点标题和页面标题的HTML5结构

css - 仅在一个 Div 中应用样式表

python - 如何将纬度/经度映射到特定的美国县?

python - 将网页抓取工具从 python 2 转换为 python 3

css - 动画图标在关键帧期间向左移动

html - 卡住标题/列 CSS

python - Matplotlib:强制子图的大小(高度)相等?

javascript - 如何使一个复选框不可点击*而不*它在浏览器中变灰?