Jinja2 Template - CSS not working

时间:2018-02-01 18:41:37

标签: python css pandas jinja2

I have a Python Project that has the following file structure

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

Here is my html template code:

<!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>

I have also used the following href

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

I am not seeing any of the css formatting in my output, which is generated using the below:

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)

I am seeing the double border on the table, and my css is as follows and should collapse the border, also the H2 text is not coming out centered.:

h2{
    text-align: center;
}

table {
    border-collapse: collapse;
}

1 个答案:

答案 0 :(得分:1)

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