Django's Syntax is not translated in the CSS Files in the Statics Folder

Viewed 31

In my django project everything is working fine ,my css file is loaded just fine, but in my css file i assigned a background image body:before{background-image: url({% static 'images/bg/bg3.jpg' %}); but it won't load as django's {% static '' %} thing is not translated by django into that image's url, and it also gives me a warning, so what should i do to make django translate that css file or what other ways should make that line work. the css file is succesfully recived by the client browser but that line is still as it is and not translated by dbjango into the image's url which creates that error.

Note: I have tried to type that line in the <head> tag in the html file and it worked but it gives me error in the code editor, there must be a better way to do that!

1 Answers

The Css file can't load django template tags.

You must refer to the Static Url path configured on your settings.py

On settings.py:

STATIC_URL = '/static/'

on your css:

  background-image: url("/static/assets/BG2.png");

Just to clarify this, this image was stored on a "assets" folder inside the static folder belonging to one of the apps.

Related