Marijus
Marijus

Reputation: 4365

CSS works only in one of three templates when extended from the same template

Okay I've got my base template and I extended it in my three other templates and it only works in one of them. I find this really strange. I'm not sure what code would relevant here so please comment what code I should post.

base:

<link rel="stylesheet" type="text/css" href="static/default.css" media="screen"/>
<title>{% block title %}Marijus Merkevicius{% endblock %}</title>
<div class="holder">{% block content %}{% endblock %}

index(css works for this template):

{% extends "base.html" %}
{% block title %}Marijus Merkevicius{% endblock %}
{% block content %}
    {% for entry in entries %}
        <h1><a href="{{ entry.category.slug }}/{{ entry.slug }}/"</h1>
        <p>{{ entry.text|safe|escape }}</p>
    {% endfor %}

{% endblock %}

detail(css doesnt work):

{% extends "base.html" %}
{% block title %}{{ entry.title }} | Marijus Merkevicius{% endblock %}
{% block content %}
    <h1>{{ entry.title }}</h1>
    <p>{{ entry.text|safe|escape }}</p>
{% endblock %}

Upvotes: 0

Views: 183

Answers (1)

<link rel="stylesheet" type="text/css" href="static/default.css" media="screen"/>

You're using a relative link. That means depending on what URL rendered this page, the URL for your CSS is changing too.

Since you're using an index template and detail template, I'm guessing the two have a different root url (typical pattern is that the detail page is a "subdirectory" of the index).

Point directly to your css file instead: /static/default.css if your css file is at example.com/static/default.css

Upvotes: 2

Related Questions