【发布时间】:2010-01-20 18:06:03
【问题描述】:
在这个模板中,
<body><p>You searched for: <strong>{{ first }} {{ last }}</strong></p>
{% if lawyers %}
<p>There are {{ lawyers|length }} schoolmates of <strong>{{ first }} {{ last }}</strong> in the database:</p>
<ul>
{% for lawyer in lawyers %}
<li> {{ lawyer.first }} {{ lawyer.last }} {{ lawyer.firm_name }} {{ lawyer.school }} {{ lawyer.year_graduated }}</li>
{% endfor %}
</ul>
{% else %}
<p><strong>{{ first }} {{ last }}</strong> has no classmates in the database. Try another lawyer.</p>
{% endif %}
我从搜索表单中选择了{{ first }} 和{{ last }},但没有选择其他参数,例如year_graduated。
但我想说:
<p>You searched for: <strong> {{ first }} {{ last }}, class of {{ year_graduated }} </strong> </p>
如何在模板中使用lawyer.year_graduated,即使它不在搜索表单中?
查看功能见my previous question。
谢谢。
【问题讨论】:
-
如果
laywer.year_graduated在所有结果中都不相同怎么办?您似乎在暗示year_graduated是一个搜索参数? -
是的,你是对的。我只在结果返回查询的同学的情况下使用这个。当有超过 1 名同名律师时,我只使用查询。