简体   繁体   English

我如何使用静态将背景图像放在带有django的CSS中的身体上?

[英]How do I put a background image on the body in css with django using static?

How do I put a background image on the body in css with django using static? 我如何使用静态将背景图像放在带有django的CSS中的身体上?

Is it something like this? 是这样吗 I can't find any information on this. 我找不到有关此的任何信息。 Thanks. 谢谢。

{% load static %}
body {
    padding: 0 20px;
    background-image: url("{% static "assets/images/2.gif" %}");
}

Use a relative path. 使用相对路径。 Relative to the folder where the css file reside. 相对于css文件所在的文件夹。

background: url('../assets/images/2.gif');

And use it in template file like this: 并在这样的模板文件中使用它:

{% load staticfiles %}
<link href="{% static 'css_file_address' %}" rel="stylesheet" media="screen">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM