I need to use data submitted by user in one view in another view. I don't want that data in the URL, and the data can not be extracted by calling the last object created, since many times it will not be that object.
My view for the index looks like this:
def index(request):
template_name = 'index.html'
if request.method == 'POST':
foo = request.POST['foo_text']
Foo.objects.get_or_create(foo=foo)
return redirect('/results/')
return render(request, template_name, {})
The template for this view is:
<html>
<title> Some Site </title>
<h1> Some site </h1>
<form action="/results/" method="POST" >
<input type="text" name="foo_text" id="id_foo_lookup" placeholder="Enter Your Foo">
{% csrf_token %}
</form>
The view to handle the data results is:
def results_view(request, foo):
template_name = 'movement_results.html'
results = Results.objects.filter(foo=foo)
return render(request, template_name, {'results' : results })
So as you can see the User will type some data, foo, into the index.html, which then gets or creates the object if it does not already exist in the database. From that the results view will return results based on the data submitted by the user previously. How do I get the foo data to the next view?