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

前端 未结 10 2064
离开以前
离开以前 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 03:13

    Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.

    In you settings.py file define STATIC_URL: STATIC_URL = '/static/'

         {% load static %}
         My image
    

    or

         #third{
              background: url('{{ STATIC_URL }}my_app/example.jpg'
         }
    

提交回复
热议问题