2013-07-26 112 views
0

template.html問題,如果條件循環

在Django是可以檢查的條件就是這樣,我得到的錯誤在這行(incident.other_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'" 

回答

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%}