I am new to Django and HTML and I am trying to display a list of data derived from a form on the HttpResponseRedirect page. I have been reading Django APIs but I am still unsure of how to use HttpResponse() and HttpResponseRedirect().
As of now I understand that response = HttpResponse() makes an HttpResponse object of and HttpResponseRedirect('results') redirects the browser to a new html template page. What I dont know is how to write results.html to display on my browser.
I need help on how to write the HTML page.
I also need help on how to pass a list of data to that html page.
I would also be ok with displaying the list on the same html page the form is in instead of loading a new page.
Current code: def contact(request):
if request.method == 'POST': # If the form has been submitted...
form = ContactForm(request.POST) # A form bound to the POST data
chosen = []
if form.is_valid():
strt = time.time()
form = form.cleaned_data
parameters = organize(form)
print 'input organized'
chosen, companies = multiple(parameters)
end = time.time()
pp.pprint(companies)
print 'companies matching search filters: ' , len(companies)
print 'total time: ' , str(end-strt)
response = HttpResponse(chosen)
return HttpResponseRedirect('results') # Redirect after POST