user1036794
user1036794

Reputation: 3

Enabling Template Inheritance in Django

Python 2.7.1 / Django 1.3

I am new to Django Templates and trying to do very simple template inheritance.

testbase.html

hello

{% block tester %}
fail
{% endblock %}

testblock.html

{% extends "testbase.html" %}

{% block tester %}
pass
{% endblock %}

result

hello fail

The two templates are in the same directory which has been added to the project settings.py file and since it finds the base template I'm having trouble finding why it wouldn't be able to find the child template.

Thanks for any ideas on what to try next.

Upvotes: 0

Views: 601

Answers (1)

Luke Sneeringer
Luke Sneeringer

Reputation: 9428

In your view, you need to make sure the template you are pointing to is testblock.html and not testbase.html.

Assuming you're using render_to_response, it would look something like:

return render_to_response('testblock.html')

If your view function is referencing testbase.html, then you'll get the unextended template. That's by design.

Here's a link to the template documentation for good measure. :)

Upvotes: 2

Related Questions