[Answer]-Django template rendering extend tag incorrectly

1๐Ÿ‘

โœ…

If you extends a base.html template, no content not surrounded by {% block %} will be rendered at all.

You could create additional {% block precontnet %}{% endblock %} in base.html, and wraps Pink/Yellow/Red in user_links.html

Or you can put Pink/Yellow/Red in {% block content %} if user_links.html and use {{ block.super }} in user_detail.html

links.html

{% extends "base.html" %}
{% block content %}
    Yellow
    Pink
    Green
{% endblock %}

user_detail.html

{% extends "user_links.html" %}
{% block content %}
    {{ block.super }}
    <h2>{{ object.username }}'s Profile</h2>
        {% if object.userprofile.bio %}
            {{ object.userprofile.bio }}
        {% endif %}
{% endblock %}
๐Ÿ‘คkmmbvnr

0๐Ÿ‘

Place div after </p> in base.html

<h1>Cool App</h1>
<div class="navbar">
<p>
    <a href="{% url 'home' %}">HOME</a> |
{% if user.is_authenticated %}
    <a href="{% url 'logout' %}">LOGOUT</a>
{% else %}
    <a href="{% url 'login' %}">LOGIN</a>
{% endif %}</p>
</div>

Try this in user_links.html

{% extends "base.html" %}
{% block content %}
Yellow
Pink
Green
{% endblock %}
๐Ÿ‘คf43d65

Leave a comment