On my homepage I have a simple search form. The user can enter some filters and in a next step the search results are diplayed on a new page => this all works:
Below a simplified version of the view.py:
def search(request):
form = SearchForm()
if request.method == 'POST':
form = SearchForm(request.POST)
results = search(form)
return render_to_response('search_results.html',{'results': results},context_instance = RequestContext(request))
else:
form = SearchForm()
return render_to_response('search.html',{'form': form},context_instance = RequestContext(request))
Now the problem:
In a next step I want to add the same searchform in the search_result.html page. The purpose would be that the user can refine the search results using that search form. In an ideal world the search form on search_results.html has already the filters entered in search.html prefilled.
I’m struggling a bit on how to approach this. Should I pass the orginal entered filters as a list to the search_result.html page? How can I do this? And how can I put these values as a default in the form? Maybe I’m overthinking this somehow, but at this moment I don’t see a good solution.
Any feedback, directions are very much appreciated!
Thanks!
Can’t you just make your context dict
{'results': results, 'form': form}? This would make the form available again with the previously posted data already bound to the form.