【发布时间】:2010-01-22 18:02:33
【问题描述】:
This application returns schoolmates of lawyers.
当用户仅搜索名字和there are more than 1 result 时,我将查询留在表单中并要求他们输入姓氏。但是我认为如果用户只是单击其中一个名称并直接返回搜索结果会更好。 (此时链接将带您再次搜索表单。)
在模板中,我需要的查询和姓氏在{% for lawyer in lawyers %} 循环中作为属性:lawyer.first 和lawyer.last。我不知道如何保存它们以创建查询。你能帮我解决这个问题吗?
注意:模板在下方,但我将 view function 放在 pastebin.com 中。它有 60 行长,我不确定是否应该在这里发布。
谢谢。
<html>
<head>
<title>Search results</title>
</head>
<body>
<p>You searched for <strong>{{ first|capfirst }} </strong>.</p>
<p>There are {{ lawyers|length }} {{ first|capfirst }} in the database. Please select one.</p>
{% for lawyer in lawyers %}
<ul><li><a href="/search/">{{ lawyer.first }} {{ lawyer.last }} {{ lawyer.firm_name }} {{ lawyer.school}} class of {{ lawyer.year_graduated }}</a></li></ul>
{% endfor %}
<form action="" method="get">
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
</body>
</html>
编辑
我需要像这样创建一个新的视图函数吗?
def new_query(request):
last_name = request.GET.get('lawyers.last')
first_name = request.GET.get('lawyer.first')
....
【问题讨论】: