arcee123 arcee123 - 2 months ago 21
CSS Question

how to add staticfiles processing to css pages in django

In my CSS, I have examples like this:

#defaultCountdown span.countdown_section {
color:#fff;
padding:7px 15px!important;
margin-bottom:2px;
font-weight:300;
background:url(../img/bg-white.png);
text-align:center
}


If you see the background tag, there's a url.
How do I serve this via staticfiles?

Thanks.

Answer

To answer your comment about using static in css or js files.... It could be done. Basically you would define a route and view just like for html pages.

But, this is strongly discouraged for a production level site. You will have a significant increase in page response time if you do this rather than serving these as static files.

To accomplish this, you simply pass content_type into your HttpResponse for your related view:

return HttpReaponse(my_dynamic_css, content_type="text/css")