0

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.

3
  • 3
    Are you rendering "testblock.html" from your view? Commented Nov 9, 2011 at 2:39
  • yes, it is being rendered from a view and I suspect the view renders the base template properly because it renders "hello fail". Seems to be a disconnect between the base view and the one containing the block. Commented Nov 9, 2011 at 8:20
  • could you please show your view (at least part of it)? Commented Nov 9, 2011 at 8:39

1 Answer 1

2

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. :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was calling the base template from the view. Got too caught up in thinking it was a problem in the templates.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.