0

Here's a link to this page https://code.djangoproject.com/ticket/5172

To be more specific this

{% for 5 %}
repeat me
{% endfor %}

and this

{% for my_integer %}
loop: {{ forloop.counter }}
{% endfor %}

mistakes that I earn is following

TemplateSyntaxError: 'for' statements should have at least four words: for 5
Krasimir
  • 1,806
  • 2
  • 18
  • 31

2 Answers2

2

I think what you want is this:

{% for i in 5|getrange %}
do something
{% endfor %}

See this code snippet.

Volatility
  • 31,232
  • 10
  • 80
  • 89
  • That requires adding the code to implement that filter, before it can be used. – Amber Jan 09 '13 at 08:21
  • @Amber Django templates don't support range functions though - http://stackoverflow.com/a/5242907/1907098 – Volatility Jan 09 '13 at 08:25
  • In rewriting the filter I get the following error TemplateSyntaxError: 'for' statements should use the format 'for x in y': for i 0 to 5 – Krasimir Jan 09 '13 at 09:13
  • @Krasimir Firstly, what's your filter? Secondly, you're meant to type `{% for i in 5|yourfilter %}` – Volatility Jan 09 '13 at 09:20
  • {% load range_tags %}
      {% for i in 3|get_range %}
    • {{ i }}. Do something
    • {% endfor %}
    This code is not working and you start. Here's the filter from django.template import Library register = Library() @register.filter def get_range(value): return range( value )
    – Krasimir Jan 09 '13 at 17:29
  • @Krasimir everything should work fine, not sure what the problem here is – Volatility Jan 09 '13 at 20:52
  • The problem is that it does not recognize django html comments and gave me error commented cycle. – Krasimir Jan 10 '13 at 07:28
1

The page you linked to is a ticket requesting such syntax. It is closed as wontfix, as in, that functionality is very specifically not available and unlikely to be added any time soon.

Instead, you'd need to use something like {% for counter in my_range %} or similar, where my_range is set to the output of range(5).

Amber
  • 507,862
  • 82
  • 626
  • 550