RankoR RankoR - 1 year ago 58
Python Question

Django templates extending and CSS

I have such base template:

<title>{% block title %}{% endblock %}</title>

<link rel="stylesheet" href="/static/style.css"/>

And this text in logs when I refresh the page:

[01/Dec/2011 18:22:00] "GET /search/ HTTP/1.1" 200 2760
[01/Dec/2011 18:22:00] "GET /static/style.css HTTP/1.1" 200 54

So, it means that CSS loads from server correctly. But it doesn't work! If I include this CSS as text directly into the base template, it works properly.
The static files configuration is OK.


Are you putting the css in a block that will put it in the head of the base?

/* base.html */
        <title>{% block title %}{% endblock %}</title>
        {% block extra_head %}{% endblock %}
        {% block content %}{% endblock %}

/* another template */
{% extends 'base.html' %}
{% block title %}My Title{% endblock %}
{% block extra_head %}
    <link rel="stylesheet" href="/static/style.css"/>
{% endblock %}
{% block content %}
    <h1>This is my page!</h1>
{% endblock %}

In your browser, how does the page source look? Is the style sheet in the head? can you click the link and see the actual css?