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

会有一股神秘感。 提交于 2019-12-25 09:29:42

问题


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 %}

回答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



来源:https://stackoverflow.com/questions/8088003/css-works-only-in-one-of-three-templates-when-extended-from-the-same-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!