2010-01-20 125 views
2

在这个模板,Django模板:如何在模板中的模型中使用字段?

<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查看功能。

谢谢。

+0

如果'laywer.year_graduated'在所有结果中都不相同怎么办?看起来你暗示'year_graduated'是一个搜索参数? – Seth

回答

2

那么,简单的方法只是将year_graduated添加到上下文字典中。

return render_to_response('search_results.html', {'lawyers': lawyers1, 'last': last_name, 'first': first_name, 'year_graduated': q_year[0], 'form': form}) 
+0

谢谢!我不知道这一点。 – Zeynel

相关问题