Question

I have a blog app and something is really bogging me. I have a base.html template that I extend in every template of my views and that works perfectly, just one of the views, which is the one that only shows the blog post and not the rest of the posts, doesn't extend the base.html even though I have the {% extends 'base.html'%} just as in every other template and everything else basically the same. Also static files aren't loading, even though I load them just as in every other template ..

base.html:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}style.css">
        <link rel="shortcut icon" href="static/favicon.ico" />
        <meta charset="utf-8">
        <title>
            {% block title %}{% endblock %}
        </title>
    </head>
    <p class="header">Blog</p>

    <body background="static/landscape.jpg">
        <div class="content">
            {% block content %}
            {% endblock %}

        </div>
    </body>
</html>

Other template(works):

{% extends 'base.html' %}
{% load staticfiles %}


{% block title %}Blog {% endblock %}

{% block content %}
    {% for post in posts %}
    <div class="post">
        <h1>
            <a class ="title" href="{{post.get_absolute_url}}">
                {{post.title}}
            </a>
        </h1>
        <p>{{post.content}}</p>

        <hr>
    </div>
    {% endfor %}
{% endblock %}

Specific template(doesn't work):

{% extends 'base.html' %}
{% load staticfiles %}
{% block title %}{{post.title}}{% endblock %}

{% block content %}
    <article>
        <header>
            <h1 style="font-size:40px;"> {{post.title}} </h1>
            <p>{{post.content|safe}}</p>
            <p class="date">
                Posted on
                <time datetime="{{post.created|date:"c"}}">
                {{post.created|date}}
                </time>
            </p>
        </header>

    </article>
    <hr>
{% endblock %}      

I'd be very thankful if you can discover anything I can't ... thanks.

Was it helpful?

Solution

This really sounds like a path issue to me. Try adding a / to your css and background paths, for example: <body background="/static/landscape.jpg"> and see if that makes a difference.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top