On Sun, 2008-01-06 at 16:12 -0600, Michael Hipp wrote:
> Peter Rowell wrote:
[...]
> > I recommend rethinking how data is passed into and used in your
> > templates. Consider creating your own content processor. Or maybe some
> > custom template tags and/or filters.  See
> > http://www.djangoproject.com/documentation/templates_python/ and
> > djangobook.com for much more on these options.
> 
> I've been reading up on this option and it may be what I'm looking for. But 
> it 
> seems surprising that such an "advanced" feature would have to be called upon 
> to do something that seems, to me, so common. But there's gotta be something 
> I'm missing. (See below)

Douglas Adams had it right: don't panic!

Really, this attitude is always a bit depressing to read. You want
something to happen for every template. There is a mechanism available
for that -- context processors -- but people don't want to use it
because they want *something else* that happens for every template.
Please think about what it is you're trying to achieve and realise that
since Django cannot read your mind, you're going to have to give it some
code to provide the data.

If you want some data to be provided every time you must either (a)
specify it every time or (b) write a function that is executed every
time that provides the data. Django gives you (b) and a way to say "run
this function for every template". It cannot possibly be any simpler
than that.

Context processors are a function that returns a dictionary. Template
tags (particularly when done using the simple_tag decorator) are
basically the same. Hardly advanced rocket surgery.

> > If you need to do all kinds of mid-template computing (which Django
> > templates are deliberately designed to discourage)
> 
> Could you elaborate please?
> 
> My web pages won't be so different, I think, than many others. Each page will 
> have "main content" and "other stuff". The "other stuff" is not related to 
> "main stuff" and therefore "main stuff" shouldn't know anything about them. 
> But lots of the "other stuff" need to be created dynamically so I have to 
> somehow invoke a method that does the job.

Templates are used to populate themselves with the data from their
contexts. They don't generate data from scratch. That's not their job.
That way lies madness (it's called PHP and ASP, amongst other nasty
names). So you need to get the data into the context in the first place.
Generating the data is the role of views, context processors and
template tags -- they are all executed at different points in the
pipeline with slightly different responsibilities, so one of them will
be the most natural fit for your uses.

Best wishes,
Malcolm

-- 
He who laughs last thinks slowest. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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