python - Django 模板 {% if %} : what does it take to be equal?

标签 python django templates

这是一段来自 Django 模板的代码:

{% for customer in customers %}
    {% for div in divs|lookup:customer %}
        <p>:{{ div.custdiv_id }}: vs. :{{ currentDiv }}: ==>
            {% if div.custdiv_id == currentDiv %}
                YES!
            {% else %}
                NOPE.
            {% endif %}
        </p>
    {% endfor %}
{% endfor %}

这是渲染模板的一些输出:

:1: vs. :1: ==> NOPE.
:7: vs. :1: ==> NOPE.
:5: vs. :1: ==> NOPE.
:9: vs. :1: ==> NOPE.

为什么 :1: 与 :1: 不打印“YES”?冒号是为了检查它是否不是一些间距问题,它似乎不是; div.custdiv_id 和 currentDiv 在它们各自的模型上来自同一类型——bigint(20)。我不知道这里的问题是什么。

最佳答案

你为什么不使用 {% ifequal div.custdiv_id currentDiv %}

关于python - Django 模板 {% if %} : what does it take to be equal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20647205/

相关文章:

python - Google App Engine 上的信用卡付款和通知

python - Pyramid 1.4 需要 WebOb 1.2b3+。 Google App Engine 提供 WebOb 1.1.1。难道这一切都要以泪水结束吗?

Django Queryset - 获取每个外键的最新记录

python - 将标签分配给Django ORM多对多关系中的对象

C++ - 通过单个指针访问多个对象的接口(interface)

c++ - 多次包含命名空间的链接器错误

python - python 中存在多个匹配项时删除两个模式之间的行

python - 如何通过 holoviz 和 NetworkX 呈现 GraphViz Dot 文件?

Django - Admin - 内联 - 基于某些条件的 'extra' 值

c++ - boost::variant 的访客模板