user9708733
user9708733

Reputation: 113

How to use background-image css property with Django static files

I know similar questions have been answered but there are no clear answers for how to do this in a linked css file, all suggest doing directly in the html file itself I have a Jobs project, with the following structure to get to the images folder:

Jobs/core/static/core/images/search.jpg

How can I set an input element's background-image property to 'search.jpg' in a css file that is referenced with <link rel="stylesheet" href="{% static 'core/css/index.css' %}" /> ? I have seen similar questions asked and all of the answers suggest things such as setting it inline on the element itself, but how can this be done in a linked css file?

Upvotes: 0

Views: 4252

Answers (1)

Diego Vin&#237;cius
Diego Vin&#237;cius

Reputation: 2223

Django cant see or write CSS files, all your CSS that needs Django static import you should put it inline (i like to create a new html files with my inline css with static urls and than include it on my template)

<div style="background-image: url({% static 'core/images/search.jpg' %});" />

Or you can use relative paths in your css files, but this will probabily give you a headache when start to setup in production

.someClass {
   background-image: url(/static/core/images/search.jpg);
}

Upvotes: 2

Related Questions