skip to Main Content

How can I insert an image into url():

<div class="panel active" style="background-image: url();">
  <h3>Business Session</h3>
</div>

I tried template tag with this {% load static %} and also absolute path but it does not work.

My image is in the static directory.

It works:

<div class="panel active" style="background-image: url('{% static 'home/daniel.jpg' %}')">
        <h3>Business Session</h3>
      </div>

But VS code highlights part of the template tag in red. Is it a good practice to do that?
enter image description here

2

Answers


  1. put your image is in static/img directory and then try doing
    background: url("/static/img/sample.jpeg"); and if that doesn’t work try using an external css file

    Login or Signup to reply.
  2. Try It Like That:

    <div class="panel active" style="background: url(/static/home/daniel.jpg)"> <h3>Business Session</h3> </div>

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search