0

模板.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'"
4

1 回答 1

2

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

  • 或者
  • 不是
  • ==, !=, <, >,“<=”, >=

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%}
于 2013-07-26T04:54:58.087 回答