user1518770
user1518770

Reputation: 61

Can't get Django Template Inheritance to work

This seems so simple and yet it refuses to work...

I have my base.html file:

{% load static %}
<html>
<head>
  <meta charset="utf-8">
  <title>
    {% block title %}
    Simple Skeleton
    {% endblock title %}
  </title>

and my home.html file:

{% extends "base.html" %}
<% block title %>
Resource List
<% endblock %>

(they are both a bit longer but I feel this is all that is necessary)

The home.html completely fails to overwrite the sections within the code blocks - the page title remains "Simple Skeleton" and not "Resource List" despite me accessing the home.html file.

What am I doing wrong?

Upvotes: 0

Views: 150

Answers (2)

user8193706
user8193706

Reputation: 2425

You have a typo error in home.html. Use {% %} for template tags instead of <% %>.

{% extends "base.html" %}
{% block title %} 
    Resource List
{% endblock %}

Upvotes: 1

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476659

Django template tags are written between {% … %}, not <% … %>, so {% block title %}, not <% block title %>:

{% extends "base.html" %}
{% block title %}
Resource List
{% endblock %}

By not using the proper template tag, Django will not render this content: it is content outside a block, so it will not have an effect on the inherited template.

Upvotes: 2

Related Questions