if条件循环中的问题

时间:2013-07-26 04:52:09

标签: python django django-models django-templates

template.html

在django中可以检查这样的情况,我在这一行收到错误(incident.other_location或location)。

{%if newreport_tab and reportperson and incident.manual_date and media  and followup and (incident.other_location or location) and incident.other_incident_type and types%}<a href="{% url incident.views.savereport %}">{% include "buttons/saveandclose.html" %}</a>{%else%}{% include "buttons/saveandclose.html" %}{%endif%}

我收到此错误

"TemplateSyntaxError at /report/savereport/
Could not parse the remainder: '(incident.other_location' from 'and(incident.other_location'"

1 个答案:

答案 0 :(得分:2)

您不能使用()(括号)来组合操作,而是可以遵循以下运算符的优先级:

  • ==,!=,&lt;,&gt;,“&lt; =”,&gt; =

or评估之前:

{%if newreport_tab and reportperson and incident.manual_date and media  and followup and incident.other_location or location and incident.other_incident_type and types%}<a href="{% url incident.views.savereport %}">{% include "buttons/saveandclose.html" %}</a>{%else%}{% include "buttons/saveandclose.html" %}{%endif%}

or评估后:

{%if newreport_tab and reportperson and incident.manual_date and media  and followup and someresult and incident.other_incident_type and types%}<a href="{% url incident.views.savereport %}">{% include "buttons/saveandclose.html" %}</a>{%else%}{% include "buttons/saveandclose.html" %}{%endif%}