I submit a form with two inputs to search a table. My code doesn't get the value of 'namequery' instead of displaying all data in table. What did I do wrong here? Thanks for any help! The url is http://..../chinook/search/?namequery=rand&affquery=
search.html
<h3 class="labs-background-title">Search results for <em id="search-name">{{ namequery }}</em>:</h3>
{% if object_list %}
{% for obj in object_list %}
{{ obj.lname }} <br />
{{ obj.clustering }} <br />
{% endfor %}
{% else %}
<h3>No matches found.</h3>
{% endif %}
views.py
class SearchView(generic.ListView):
model = Pitable
template_name = 'chinook/search.html'
def get_queryset(self):
try:
namequery = self.kwargs['namequery']
except:
namequery = ''
if (namequery != ''):
object_list = self.model.objects.filter(lname = namequery)
else:
object_list = self.model.objects.all()
return object_list
The return page display all data, shows the {{namequery}} is empty. Thanks!