Created
February 26, 2016 19:50
-
-
Save dafma/656b6e2878c5d06d6922 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment