I have a simple search app within a Django project which searches within a CMS admin. This is the form that generates the URL:
< form method="get" action="/search">
< p>< label for="id_q">Search:
< input type="text" name="q" id="id_q" />
< input type="submit" value="Submit" />< /p>
, this is the URL:(r'^search/$', 'search.views.search'),this is the view:
def search(request):
query = request.GET['q']
results = FlatPage.objects.filter(content__icontains=query)
template = loader.get_template('search/search.html')
context = Context({ 'query': query, 'results': results })
response = template.render(context)
return HttpResponse(response), this is the template:< html>
< head>
< title>Search page
< /head>
< body>
< p>You searched for "{{ query }}"; the results are listed below.< /p>
< ul>
{% for page in results %}
< li>< a href="{{ page.get_absolute_url }}">{{ page.title }}< /a>< /li>
{% endfor %}
< /ul>
< /body>
< /html>
but I keep receiving this error :"Key 'q' not found in < QueryDict: {} >". Does anyone why and what can I do?