当我过滤我的搜索栏时,我得到这个错误。我不确定我在这里做错了什么
观看本教程:https://www.youtube.com/watch?v=llbtoQTt4qw&t=3399s
查看次数.py
class pplList(LoginRequiredMixin,ListView):
model = People
context_object_name = 'people'
def get_context_data(self,**kwargs):
search_input = self.get.GET.get('search-area') or ''
if search_input:
context['people'] = context['people'].filter(name__icontains=search_input)
return context
人员列表.html
{%if request.user.is_authenticated %}
<p>{{request.user}}</p>
<a href="{% url 'logout' %}">Logout</a>
{% else %}
<a href="{% url 'login' %}">Login</a>
{% endif %}
<hr>
<h1>Interviewee Dashboard {{color}}</h1>
<a href="{% url 'pplCre' %}"> Add Candidates</a>
<form method="get">
<input type = 'text' name = 'search-are'>
<input type = 'submit' value = 'Search'>
</form>
<table>
<tr>
<th> Item</th>
<th> </th>
</tr>
{% for people in people %}
<tr>
<td>{{people.name}}</td>
<td><a href="{% url 'pplDet' people.id %}">View</a></td>
<td><a href="{% url 'pplUpd' people.id %}">Edit</a></td>
<td><a href="{% url 'pplDel' people.id %}">Delete</a></td>
</tr>
{% empty %}
<h3>No items in list</h3>
{% endfor %}
</table>
1条答案
按热度按时间ffx8fchx1#
有一些小错误,比如它应该是
self.request.GET.get('search-area')
,而且你还没有调用super()
方法,所以试试这个视图:此外,基于类的视图通常用PascalCase编写,因为它们是Python的类,需要将它们的名称写为模型名称作为前缀,实际视图名称作为后缀,因此应该是
PeopleListView
。