【问题标题】:Comparing the i from loop with the passed value将 i from 循环与传递的值进行比较
【发布时间】:2012-03-27 01:48:09
【问题描述】:

我在 Google App Engine 网页中使用 Django 1.2 模板。

我将agemin 传递给模板以将选项标记为在 html 表单中选择。 但是下面的代码不起作用。

agerange(18,100) 创建

如何比较'i'和agemin?

    {{agemin}} //this is for example 23
    <select name=agemin><BR>
        {% for i in age%}
            <option {% if i == agemin %}selected{% endif %}>{{ i }}</option>
        {%endfor%}

    </select>

【问题讨论】:

    标签: python google-app-engine django-templates


    【解决方案1】:

    使用ifequal 标签:

    {% ifequal agemin i %}
    

    【讨论】:

    • 我试过了,它也不起作用。它看起来很奇怪,但两种方法都不起作用。只是猜测,但可能是因为数据类型? (即 int 和 text?)
    • 是的,这也很重要。检查agemin是否为整数。
    • Thrustmaster:谢谢,agemin 作为文本值传递,'i' 是整数
    猜你喜欢
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    相关资源
    最近更新 更多