I
I
Ilya Garbazhiy2020-02-24 14:58:51
css
Ilya Garbazhiy, 2020-02-24 14:58:51

How to put an image on background in html in python django?

I want to put an image in the background of an HTML template, but it displays a white background. Path to the image
PROJECT_DIRECTORY/static/bg.jpg .
In settings.py it says:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

In the HTML style tag:
body {
  background-image: url({% static "bg.jpg"%});
  background-size: 100hv;
  background-attachment: fixed;
}

When you go to the page and look at the source code, it says
background-image: url(static/bg.jpg);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question