Python 背景设置烧瓶中的背景图像

Python 背景设置烧瓶中的背景图像,python,flask,Python,Flask,伙计们,我知道这有很多答案,但对我来说不行。我试图在应用程序的init中指定url,但对我来说仍然不行。我是否遗漏了什么?我正在尝试将背景更改为图像 这是我的目录 └── wine ├── __init__.py ├── __init__.pyc ├── __pycache__ │ ├── __init__.cpython-37.pyc │ ├── models.cpython-37.pyc │ └── routes.cpython-3

伙计们,我知道这有很多答案,但对我来说不行。我试图在应用程序的init中指定url,但对我来说仍然不行。我是否遗漏了什么?我正在尝试将背景更改为图像

这是我的目录

└── wine
    ├── __init__.py
    ├── __init__.pyc
    ├── __pycache__
    │   ├── __init__.cpython-37.pyc
    │   ├── models.cpython-37.pyc
    │   └── routes.cpython-37.pyc
    ├── models.py
    ├── routes.py
    ├── site.db
    ├── static
    │   ├── bg.jpeg
    │   ├── main.css
    │   ├── pexels-photo-935240.jpeg
    │   ├── pexels-photo.jpg
    │   └── sf.jpg
    └── templates
        ├── index.html
        └── rec.html
这是我为flask安装的materialize html文件

    {% extends "material/base.html" %}
{% import "material/wtf.html" as wtf %}
<head>
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
    {% block title %}
    Welcome
    {% endblock %}
</head>

{% block content %}

<div class="container">
    <h1>Whats Your Taste</h1>
    <div class="row">
        <form method="POST" action="/">
            {{ wtf.quick_form(form)}}

        </form>
    </div>
</div>

{% endblock %}

不能在静态CSS文件中使用Jinja。您需要将URL引用更改为绝对URL,或将CSS规则放置在实际的Jinja模板中。

尝试以下操作: 背景图像:url(“bg.jpeg”)

您必须指定图像文件的路径。在您的设计中,css和jpeg位于同一文件夹中,因此只需在url()中提及图像名称即可

对html模板使用jinja


有关如何指定路径的信息,请参见此处

请在此处添加一些说明,不要只发布链接。更新了答案。我仍然找不到方法
body{
    background-image: url({{ url_for ('static', filename = 'bg.jpeg') }});
}