> How to use Loop counter iteration (ie) looping 10 time in Django
> Template language (html)
use 'for'
--
regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/
> Can u give some example since for iteration over a array or a
> dictionary
http://www.djangoproject.com/documentation/templates/#for
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.
from django.template.defaultfilters import stringfilter
@stringfilter
def range(value): return range(int(value))
def your_view(request):
...
some_subset = Model.objects.all()[:10]
...
Add it to 'extra_context' and you won't need to do anything trickier than this:
{% for model in some_subset %}
some stuff
{% endfor %}
--
portfolio: http://textivism.com/
blog: http://erikanderica.org/erik/