范围不适用于for循环 [英] Range not working in for loop

查看:52
本文介绍了范围不适用于for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的for循环无法正常工作,我不确定为什么。

My for loop is not working and I'm not sure why.

这是循环:

{% for i in range({{text|length}} + {{images|length}}) %}

text images 是我传递给的查询集

text and images are querysets I have passed to the template from the view.

我得到的错误是:


django.template.exceptions.TemplateSyntaxError:'for'语句应使用格式'for x in y':for i in range({{text | length}} + {{images | length}})

django.template.exceptions.TemplateSyntaxError: 'for' statements should use the format 'for x in y': for i in range({{text|length}} + {{images|length}})

对我来说这没有意义,因为在我看来,它确实遵循错误所建议的格式。

This doesn't make sense to me, as it looks to me as if this does follow the format suggested by the error.

推荐答案

{% for i in range((text|length) + (images|length)) %}

那应该解决它。 {{}}用于其他目的。我在jinja2中遇到了自己的问题,以前从未使用过。我的循环是:

That should fix it. The {{}} are used for another purpose. I have my own problem in jinja2 and haven't used it before. My loop is:

{% for i in range(string1|length) %}

它有效

这篇关于范围不适用于for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆