- Author:
- zalun
- Posted:
- March 9, 2009
- Language:
- HTML/template
- Version:
- Not specified
- Score:
- 6 (after 7 ratings)
Easy to use range filter. Just in case you have to use a "clean" for loop in the template.
Inspired by Template range tag
Copy the file to your templatetags and load them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | from django.template import Library
register = Library()
@register.filter
def get_range( value ):
"""
Filter - returns a list containing range made from given value
Usage (in template):
<ul>{% for i in 3|get_range %}
<li>{{ i }}. Do something</li>
{% endfor %}</ul>
Results with the HTML:
<ul>
<li>0. Do something</li>
<li>1. Do something</li>
<li>2. Do something</li>
</ul>
Instead of 3 one may use the variable set in the views
"""
return range( value )
|
More like this
- Bootstrap Accordian by Netplay4 5 years, 10 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
- Bootstrap theme for django-endless-pagination? by se210 8 years, 10 months ago
- Reusable form template with generic view by roldandvg 8 years, 11 months ago
- Pagination Django with Boostrap by guilegarcia 9 years, 1 month ago
Comments
This should be a default filter
#
@pro547 I second that!
Thanks for the snippet! :)
#
simple and great!
#
for one based, you can add 1 via a list comprehension
#
Would it make more sense to call this as_range instead of get_range?
#
This doesnt work tho:
But this works fine:
#
Please login first before commenting.