arcee123 arcee123 - 1 year ago 70
CSS Question

how to add staticfiles processing to css pages in django

In my CSS, I have examples like this:

#defaultCountdown span.countdown_section {
padding:7px 15px!important;

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


Answer Source

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")