【问题标题】:Jinja2 Template - CSS not workingJinja2 模板 - CSS 不工作
【发布时间】:2018-02-01 18:41:36
【问题描述】:

我有一个具有以下文件结构的 Python 项目

 days_on_hand.py
 templates\
    doh_managers.html
 static\
    style.css

这是我的 html 模板代码:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <link rel= "stylesheet" type= "text/css" href= "/static/style.css">
    <title>{{ title }}</title>
</head>
<body>
    <h2>Days Inventory on Hand -- Warehouse</h2>
     {{ managers_days }}
</body>
</html>

我也用过以下href

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

我的输出中没有看到任何 css 格式,这是使用以下内容生成的:

template_vars = {"title": "Days Inventory on Hand -- Warehouse",
                             "managers_days": df.to_html(index=False)}
html_out = template.render(template_vars)
html_file.write(html_out)

我看到桌子上有双边框,我的css如下,应该折叠边框,H2文本也没有居中。:

h2{
    text-align: center;
}

table {
    border-collapse: collapse;
}

【问题讨论】:

  • 请提供您所看到的和您所期望的。

标签: python css pandas jinja2


【解决方案1】:

如果您的style.css 文件位于项目的static 文件夹中,那么要通过Flask WSGI 提供资源,您必须在href 中为样式表使用url_for('static', filename='style.css')

【讨论】:

  • 我从那个开始,但仍然没有得到预期的结果
猜你喜欢
  • 2020-10-24
  • 1970-01-01
  • 1970-01-01
  • 2015-06-19
  • 2021-05-28
  • 2012-11-29
  • 1970-01-01
  • 2022-01-12
  • 2014-09-21
相关资源
最近更新 更多