简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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