我想知道是否有一种方法可以在ifnotequal django模板标记中包含两个条件,以便同时检查这两个条件。例如:
{% ifnotequal cond1 and cond2 %}
#do something here
{% endifnotequal %}
#This code doesn't seem to work though或者还有其他方式,其中有两个条件,每个条件包含django模型实例的两个字段之间的相等比较。我在模板中的确切代码是:
{% ifnotequal user.profile.rollno applied_job.student_id %}
{% ifnotequal job.company applied_job.student_applied_job %} 我希望上述两个条件同时进行评估。还有其他更好的方法吗?
发布于 2017-04-20 06:53:05
引用django文档的话说,{% ifnotequal %}是不推荐的,所以不要使用它。
{% ifequal a b %}. {% endifequal %}是一种过时的编写{% %的方法,如果== b %}…{% endif %}。同样,如果a != b %}. {% endif %},则{% endifnotequal %}被{%取代。ifequal和ifnotequal标记将在未来的版本中被废弃。
相反,您可以使用{% if a != b %}
就你而言:
{% if user.profile.rollno != applied_job.student_id and job.company != applied_job.student_applied_job %}
<!-- Write your markup here-->
{% endif %}https://stackoverflow.com/questions/43511190
复制相似问题