I'm having trouble working with inherited code to make a functional search bar. I've been having the most trouble properly creating a search_results page.
I stripped down my search_results page to having only one line. search_results.html: <div>You searched for {{ query }}</div>
but right now, the search_results page doesn't render {{ query }}. No text that the user previously entered appears. All that shows up on that page is "You searched for"
searchbox.html
<form class="search" action="{% url 'search' %}" method='post'>
{% csrf_token %}
<input type="search" placeholder="Search here..." name="usr_query"
value='{{ query }}' required>
<button type="submit">Search</button>
</form>
views.py
def search(request):
query = request.POST['usr_query']
print "QUERY: "
print query
t = loader.get_template('gtr_site/test_search_results.html')
c = Context({ 'query': query,})
return HttpResponse(t.render(c))
I was getting a little cautious and added that "print" statement... and it does print out what the user enters in the search bar. But that isn't being generated on my search_results page.
Whats the reasoning for this?
edit:
Adding urls.py
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^about/$', views.about, name='about'),
url(r'^contact/$', views.contact, name='contact'),
url(r'^search_engine/$', views.statement_search_engine, name='statement-search') # <- url for searchbox.html,
url(r'^test_search_results/$', views.search, name='test-search'), # <- url for searchresults.
url(r'^(?P<statement_id>.+)/$', views.statement_page, name='statement'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)