0

I'm trying to put background image inside HTML document using following code

<body style="background-image: url( {{url_for('static', filename='img/library2.jpg') }} )">

But it just doesn't work. My console output is:

127.0.0.1 - - [23/Jan/2017 23:21:12] "GET /index HTTP/1.1" 200 -
127.0.0.1 - - [23/Jan/2017 23:21:12] "GET /static/styles.css HTTP/1.1" 200 -
127.0.0.1 - - [23/Jan/2017 23:21:15] "GET /static/img/favicon.ico HTTP/1.1" 200 

So I don't even have get request for the img/library2.jpg. Not sure what I'm missing

morea030
  • 420
  • 7
  • 18
  • and what do you get in HTML after rendering it ? – furas Jan 23 '17 at 23:11
  • regular white background, as if nothing about background is specified, other elements are fine. – morea030 Jan 23 '17 at 23:16
  • I don't ask what you see in browser but I ask about HTML - source code - which is displayed in browser. Browser has function "show source code" so you can see what you have in `style="background-image: ..."` – furas Jan 23 '17 at 23:19
  • BTW: [Why an inline “background-image” style doesn't work in Chrome 10 and Internet Explorer 8?](http://stackoverflow.com/questions/5846637/why-an-inline-background-image-style-doesnt-work-in-chrome-10-and-internet-ex) – furas Jan 23 '17 at 23:22
  • Sorry, my bad, only tag no style attribute – morea030 Jan 23 '17 at 23:24
  • body even without `style="background-image:` ? then you have to use wrong file to render page. – furas Jan 23 '17 at 23:25
  • Yes even without style="background-image: . Well, I'm rendering index.html which inherits (via Jinja2 inheritance) from base.html. The problem code is within base.html. Everything else inherits and renders just fine. – morea030 Jan 23 '17 at 23:33
  • it seems you put `style` in one file but `jinja` uses different file to render page. I don't know what you have in `base` and `index` but usually `` is in `base` and you should use `style` in this file. – furas Jan 23 '17 at 23:39
  • Ok, my base was inheriting from "bootstrap/base.html", so jinja probably rendered body from that file. It works just fine without it. Since your comments lead me to the solution I would like to accept your answer if you answer it (copy the last comment or something) – morea030 Jan 23 '17 at 23:48

1 Answers1

1

It seems you put style in one file but jinja uses different file to render page.

I don't know what you have in base.html and index.html but usually <body> is in base.html and you should use style in this file.

furas
  • 134,197
  • 12
  • 106
  • 148