Xar
Xar

Reputation: 7910

Why is my Django template inheritance not working?

I'm working with Django1.8.

I can't overtwrite the version_tag block in my base.html file. It always appears the default content.

This is a simplified version of my base.html:

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="{% static 'myApp/img/favicon.png' %}" rel="icon" type="image/png" />
    <title>{% block title %}{% endblock %}</title>

    <link rel="stylesheet" type="text/css" href="{% static 'myApp/lib/css/bootstrap.min.css' %}" />
    <link rel="stylesheet" type="text/css" href="{% static 'myApp/lib/css/themes/bootstrap.min.css' %}" />

    <script type="text/javascript" src="{% static 'myApp/lib/js/jquery.min.js' %}"></script>
</script>

  </head>
  <body>
    <div id="main">
      {% block menu %}
      {% include "myApp/menu.html" %}
      {% endblock menu %}
      <div id="container" class="container-fluid">
      {% block content %}
      {% endblock content %}
      </div>
    </div>
    {% block version_tag %}Default Version{% endblock version_tag %}
  </body>
</html>

On the same folder I have the version_tag.html file:

{% extends 'myApp/base.html' %}

{% block version_tag %}
V. 1.2.3
{% endblock %}

What am I missing or doing wrong? Why does it always appear Default Version instead of V. 1.2.3?

Upvotes: 1

Views: 2213

Answers (1)

Sayse
Sayse

Reputation: 43300

There are only two possible causes I can think of:

  1. Your view is still trying to render base.html instead of your inherited html template.

    Simply change the view to call the correct one (version_tag.html)

  2. The template you're really trying to display is still inheriting from base.html instead of version_tag.html

Upvotes: 4

Related Questions