I just need to generate some test content for my template. Something like:
{{ for i < 20 }}
<img src="image-{{i}}.jpg " />
{{ endfor }}
I 开发者_开发百科have no list, how should I proceed?
Well, it stucks up if you don't have a list or a iterable on template. DJango doesn't provide a default way to write dummy data. But it does provide lorem
tag to get some dummy text. See here.
But you can do an exercise though to get working what exactly you are trying to do.
Create a custom templatetag, as myutilities.py
and add to templatetags
directory of your app
.
from django import template
register = template.Library()
@register.filter
def range(value):
return range(value)
Template
{% load myutilities %}
{% for i in 50|range %}
{{ forloop.counter }}<img src="image-{{i}}.jpg " />
{% endfor %}
http://djangosnippets.org/snippets/779/
http://djangosnippets.org/snippets/1357/
精彩评论