在烧瓶中设置背景图像

伙计们,我知道对此有很多答案,但它对我不起作用。我试图在应用程序的初始化中指定 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

这是我为烧瓶安装的 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 'main.css'


body{

    background-image: url({{ url_for ('static', filename = 'bg.jpeg') }});

}


摇曳的蔷薇
浏览 110回答 2
2回答

喵喔喔

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

RISEBY

试试这个: background-image: url("bg.jpeg");您必须指定图像文件的路径。在您的设计中,css 和 jpeg 位于同一文件夹中,因此只需在 url() 中提及图像名称。将 jinja 用于 html 模板。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python