python - Django, creating a functional search bar and search results page -
i'm having trouble working inherited code make functional search bar. i've been having trouble creating search_results page.
i stripped down search_results page having 1 line. search_results.html: <div>you searched {{ query }}</div>
right now, search_results page doesn't render {{ query }}. no text user entered appears. shows on page "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 getting little cautious , added "print" statement... , print out user enters in search bar. isn't being generated on search_results page.
whats reasoning 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 searchbox.html, url(r'^test_search_results/$', views.search, name='test-search'), # <- url searchresults. url(r'^(?p<statement_id>.+)/$', views.statement_page, name='statement'), ] + static(settings.static_url, document_root=settings.static_root)
change value='{{ request.get.usr_query }}'
value="{{ query }}"
right forcing show parameter. works on initial page load (which typically get) @ point haven't done searching. submit search (properly in opinion, debatable) post. search function uses post parameter , returns in in context query
, correct. display value of usr_query - not exist @ point because page posted page. change value=
, should work.
wiki
Comments
Post a Comment