Reputation: 1479
I am trying to set up a website where users can search for a job by zip code/city/state etc. I am having difficulty passing the search value to a view (I have seen this question asked before, but only when the url is expecting a value from an object i.e job.id
, but I am trying to get input from a user). Here is my code:
urls.py:
path('search_results/<str:search_input>', job_views.search_results, name = 'search_results'),
views.py:
def search_results(request, search_input):
return HttpResponse(search_input) # just trying to see if I have the search_input value
template (form is in index.html):
<form action="{% url 'search_results' search_input %}" method="post">
Right now I get Reverse for 'search_results' with arguments '('',)' not found. 1 pattern(s) tried: ['search_results\\/(?P<search_input>[^/]+)$']
. Thanks for any help.
Upvotes: 0
Views: 232
Reputation: 1629
def search_results(request, search_input):
if request.method=='POST':
return HttpResponse(search_input)
Pass search_input as string from template.
<form action="{% url 'search_results' 'search_input' %}" method="post">
Upvotes: 1