Immanuel
Immanuel

Reputation: 49

How to use a style attribute within a {% static %} tag?

This is html line which throws an error in VScode:

style="{% static 'background-image:url(images/home_slider.jpg)' %}"
  1. } expected
  2. at-rule or selector expected
  3. Do not use empty rulesets how to resolve it?

Upvotes: 1

Views: 117

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477607

The {% static … %} template tag [Django-doc] will only translate the parameter to a URI. It does not know in what "context" it is working. If you want to pass a static image in the url(..) of style fragment, you can do this with:

style="background-image:url({% static 'images/home_slider.jpg' %})"

Upvotes: 1

Related Questions