For some reason, I cannot seem to get template inheritance working and
I have tried everything I can think of, so now I'm asking here. My
problem is this: When I use one template, everything works fine. But
as soon as I try to offload some of the code in a child, it just
doesn't show up. Here are my files:
In my settings file I have added the template directory:
TEMPLATE_DIRS = (
"/home/dtdannen/Projects/contestron/contestron1/templates",
)
My views.py points to the right place. Here is my 'base' or 'parent'
file (filename "problems_index.html"):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- link CSS here -->
<title>Welcome to the problems page! Happy Coding :)</title>
</head>
<body>
{% block problist %}
<h3>No problems currently exist, check back soon for new
problems....</h3>
{% endblock problist %}
<hr />
<p align="center">This is where the standard footer will go...</p>
</body>
</html>
This file works just fine. In fact, if I just substitute the code from
the child and paste it into here (where the {% block problist %} is)
everything works. I know that its not a problem with my variables or
my database. Here is my 'child' file (filename
"problems_index_problist.html"):
{% extends "problems_index.html" %}
{% block problist %}
<h1>TEMPLATE INHERITANCE IS WORKING!!!!</h1>
{% for prob in problems_list %}
<h3>Description:</h3>
<p>{{ prob.description }}</p>
<h3>Solution:</h3>
<p>{{ prob.solution }}</p>
<hr />
{% endfor %}
{% endblock problist %}
No matter what I do, when I visit the parent, it just displays the
default value inside {% block problist %} as if the child doesn't
exist. Both the child and parent files are in the same directory, the
directory I listed in my settings under template dirs.
I have spent like 2 hours trying to figure this out, reading stuff
online, and nothing so far. Any help will be very much appreciated.
Thank you,
Dustin
P.S. I know my files might seemed to be named funny, but that's
because I wasn't sure if the actual filename of the parent and/or
child matter to the template system. Any advice on this would be
great.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.