The way to use background-image in css files with Django

前端 未结 10 1900
离开以前
离开以前 2021-02-05 02:12

I\'d like to use an image file as a background-image on Django. But I do not know how. First, I read this and tried to write like following this in a css file.

10条回答
  •  不知归路
    2021-02-05 02:55

    Here is the structure of directories for my project so you can be in context of why i'm using the URL's i am using and so you can adapt it to your project. Root directory is the folder than contains the project and apps. I have 4 apps (contacto, galeria, inicio, mapa) and the "WebCalistenia" which is the folder generated when you create a project. There i have static folder with a child called as the father ("WebCalistenia") which has two childs "/css" and "/img"

    enter image description here

    This is what worked for me. Firstly you have to {% load static %} on your HTML.

    {% load static %}
    
    
    
    ...
    

    Now you'll link the CSS to HTML

        
    

    Finally on the css file you will write:

    background: url("../img/image_name.jpeg");
    

提交回复
热议问题