On Mon, Jul 14, 2008 at 11:54 PM, Gregg Lobdell <[EMAIL PROTECTED]> wrote:
> I'm converting an application from hand-constructed Python that builds
> a large web site to Django templates.  The site has multiple layers.
> All pages share the same basic layout, header, footer, etc.  On each
> intermediate layer, some features are added, but there are several
> flavors of page within each layer.  I thought I could arrange it as
> follows:
>
> base.html
> -------------------------
> <html>
> <head><title>{{title}}</title></head>
> <body>
> Header Stuff<p>
> {%block contents%}{%endblock%}
> Footer Stuff<p>
> </body></html>
> -------------------------

This is a valid Django template.

> layer1.html
> -------------------------
> {%extends base.html%}
> {%block contents%}
> Layer One has cool {{noun}}.<p>
> {%block layer_special%}More layer specialization here, that will be
> filled in later.{%endblock%}
> Layer One closing stuff.<p>
> {%endblock%}
> -------------------------

This template is valid as well, but it doesn't do what you think: it
extends the template that base.html evaluates to instead of extending
the template named "base.html".

To use the literal value "base.html", you need to put quotes around
the template name:

  {% extends "base.html" %}

> layer1-special1.html
> -------------------------
> {%extents layer1.html%}
> {%block layer_specials%}
> You need more than {{noun}}.  You can be special.  Sometime you gotta
> {{verb}}.<p>
> {%endblock%}
> -------------------------

Aside from the typo ("extents" should be "extends"), this is fine.

> In Python:
> from django.template import Context, Template, loader
> t = loader.get_template("layer1-special1.html")
> c = Context( { "title":"Layer One Special One", "noun":"Stuff",
> "verb":"Django" } )
> print t.render(c)
>
> should print:
>
> <html>
> <head><title>Layer One Special One</title></head>
> <body>
> Header Stuff<p>
>
> Layer One has cool Stuff.<p>
>
> You need more than Stuff.  You can be special.  Sometime you gotta
> Django.<p>
>
> Layer One closing stuff.<p>
>
> Footer Stuff<p>
> </body></html>

In that case you'll need to make sure you're using either
layer_special or layer_specials as a block name.  ;-)


Arien

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to