I feel like something like this already exists somewhere, but you can simply
write a filter that turns a number into a range:
so in your templates you would have:
{% for i in 10|range %}
...
{%endfor%}
and your template filter would simply be:
from django.template.defaultfilters import stringfilter
@stringfilter
def range(value): return range(int(value))
On Tue, Apr 15, 2008 at 12:07 PM, Kenneth Gonsalves <[EMAIL PROTECTED]>
wrote:
>
>
> On 15-Apr-08, at 9:04 PM, Darryl Ross wrote:
>
> > Duke wrote:
> >> They are looping over a list
> >> I am looking for
> >> for (i = 0; i < 10; i++) {
> >> printf("Hello, World!);
> >> }
> >> link for looping statement
> >
> >
> > I am not aware of any tag that will allow you to do that, out of
> > the box. You have two options, the first is to create a custom
> > template tag that do what you want[1]. This shouldn't really be
> > terribly difficult to do.
> >
> > The second option would be to just pass in a variable into the
> > context with a list containing the number of items of the number of
> > times you want to loop. Using generic views, this could be done in
> > your urls.py like:
> >
> > ...
> > ('^$', 'direct_to_template',
> > { 'template_name': 'homepage.html',
> > 'extra_context': {'looper': range(10) }})
> > ...
> >
> > Then you can use the standard {% for %} tag:
> >
> > {% for i in looper %}
> > {{i}}
> > {% endfor %}
> >
> >
> > [1] http://www.djangoproject.com/documentation/templates_python/
> > #extending-the-template-system
> >
>
> where is the use case for this? I cannot conceive of any situation
> where one would want to loop over an arbitrary number.
>
> --
>
> regards
> kg
> http://lawgon.livejournal.com
> http://nrcfosshelpline.in/code/
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---