On Mon, 2009-03-09 at 21:47 -0700, Rama Vadakattu wrote:
> understood.
> 
> But Malcom,
> 
> 1.i feel doing restructuring of data in views for this purpose is not
> appropriate.

Then you are free to write a template filter to do what you like. It's
probably about three lines long.

> 2.And also It would be better if we can have tag / filter  which
> directly gives us an element from the list by taking position as its
> input.

Fortunately, Django allows you to write one. In fact, writing filters to
do things like this is encouraged. It's a feature.

>    such as..........   {{ list|forloop.counter }}. May be in django
> next release.........

Pretty much no chance, I suspect. Indirect variable lookups are pretty
much "programming in templates". The idea, if you're wanting to use the
templates without additions, is to structure the data in the view
function so that the template just dumps data into holes in the
structure it provides. If you're having to compute which piece of data
to get based on some other piece of data, then you can do that in this
great language we've provided called "Python".

That might sound arbitrary and I'm partially writing tongue-in-cheek,
but the principle is very sound. Once you start having arbitrary
language constructs in templates, the line between what logic to put in
the template and what to keep in the Python function that produces the
data becomes blurry and very inconsistent. Django's default setup
strives to keep that line pretty clean.

Some people don't like where the line is, which is fine. There's no
satisfying everybody and it's one of the great reasons to permit and
encourage custom template tags and filters and sharing thereof. The
ability to make extensions is a first-class feature of Django's
templates, not some accidental side-effect. And if that still doesn't
satisfy you, you can also use pretty much any other templating language
you like (even PHP) to render the results. I'd still encourage thinking
about how to keep that kind of logic out of the template, having
maintained some pretty large collections of templates in Turing-complete
templating languages that steadily became harder and harder to control,
but it's up to you which trade-offs you want to make as far as balancing
"the now" and "the future".

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to