python - 难以在 Flask 的模板文件夹中将外部 CSS 和 bootstrap 文件包含在 HTML 中

标签 python html css flask

在 Flask 编程中,我在访问 localhost:5000 内的 HTML 内的 CSS 和 Bootstrap 文件时遇到困难。

我已经尝试将 CSS 文件包含在静态文件夹中,但它不起作用。

<head>
<title>HOME PAGE</title>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='bootstrap.css') }}">

<link rel="stylesheet" href="{{ url_for('static', filename='homestyle.css') }}">

我希望所有 CSS 模块都能毫无障碍地包含在 HTML 文件中。

最佳答案

试试这个:

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

编辑:确保您的文件夹结构符合以下内容:

static/
├── homestyle.css
├── bootstrap.css
templates/
├── index.html
app.py

静态文件夹应该在根目录下,在模板文件夹内。

关于python - 难以在 Flask 的模板文件夹中将外部 CSS 和 bootstrap 文件包含在 HTML 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55350112/

相关文章:

python - 亚马逊Python 2.7 Lambda : DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so"

python - 通用协议(protocol) : mypy error: Argument 1 has incompatible type . ..;预期的

html - 动态内部样式不覆盖外部样式

javascript - ionic Angular ion-content 填充问题

python - 查找 numpy.where 返回的值的数量

python - pandas to_csv 输出引用问题

javascript - Angular JS - 错误 : ng:areq Bad Argument Argument 'GameContoller' is not a function, 未定义

javascript - 在 IE 10 中查看生成的源

javascript - Vue 元素不通过 v-show 隐藏

css - 如何仅设计一个特定的 angular-ui-bootstrap 工具提示以使其更宽?