Jinja 范围在 Django 视图中引发 TemplateSyntaxError
Jinja range raises TemplateSyntaxError in Django view
在 django jinja2 模板中使用代码
{% for i in range(10) %}
foo {{ i }}<br>
{% endfor %}
a TemplateSyntaxError
引发错误消息
Could not parse the remainder: '(10)' from 'range(10)'
我需要做什么才能遍历 jinja2 模板中的 range。
我在 django 文档中找到 link 解释
Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display.
但我认为这不适用于范围函数。
Django 使用的不是 Jinja2,而是 Django 模板语言。 Django模板语言中没有range函数
在 django jinja2 模板中使用代码
{% for i in range(10) %}
foo {{ i }}<br>
{% endfor %}
a TemplateSyntaxError
引发错误消息
Could not parse the remainder: '(10)' from 'range(10)'
我需要做什么才能遍历 jinja2 模板中的 range。
我在 django 文档中找到 link 解释
Because Django intentionally limits the amount of logic processing available in the template language, it is not possible to pass arguments to method calls accessed from within templates. Data should be calculated in views, then passed to templates for display.
但我认为这不适用于范围函数。
Django 使用的不是 Jinja2,而是 Django 模板语言。 Django模板语言中没有range函数