Use template language correctly in CSS files

I am trying to pass a CSS file via url.py file to use template tags in my CSS.

Here is my code.

base.html:

<head>
...
<link rel="stylesheet" type="text/css" href="/site_media/css/wideTitle.css" />

urls.py:

(r'^site_media/css/wideTitle.css','lightbearers.views.viewWideTitle'),

views.py:

def viewWideTitle(request):
    contentListAbout = About.objects.filter(Q(startDate__lte=datetime.now())).order_by('-startDate')
    if len(contentListAbout) > 0:
        contentAbout = contentListAbout[0]
    else:
        contentAbout = None
    ...
    return render_to_response('wideTitle.css', {'contentAbout':contentAbout, ...},
                              context_instance=RequestContext(request))

settings.py:

TEMPLATE_DIRS = (
    os.path.join(PROJECT_PARENT, "templates"),
    os.path.join(PROJECT_PARENT, "media/css"),
)

wideTitle.css (in / media / css):

#wideTitle{
    clear:both;
    height:180px;
    padding-left:0px;
    background: url({{ contentAbout.headerImage.url }}) no-repeat top left;
}

I can access the CSS file by entering its URL in my browser, but Base.html does not read it at all. I think everything is decent with me; I looked here and here for tips. Does anyone have any ideas?

+5
source share
1 answer

Is a stylesheet with the correct mime type generated? If not, the browser cannot interpret it as CSS.

, render_to_response content_type='text/css , , Django mime.

: @TommasoBarbugli , mimetype render_to_response.

( Firefox Firebug - Chrome/Safari mime stylesheets.)

+2

All Articles