Django resubmits blank form after successful form
I'm new to Django and I'm trying to make a site where after a user inputs a start and end date, some data processing is done and then a result is displayed. I have this working, but after the form successfully completes and displays the data, a new POST and GET request run on the server and find no input. This is causing me problems with another form on the same project.
I think I may need to use redirect to avoid double form submission? However, I am trying to process data with the post request and display, and to my understanding, the redirect would take the user to a new url and not pass the processed data with it.
Thanks in advance!
Here is part of my index.html
<div class="search-container">
<form action="{% url 'get_data' %}" method="post">
{% csrf_token %}
{{ timeform}}
<input type="Submit" name="submit" value="Submit"/>
</form>
And here is my forms.py
from django import forms
class PickTimesForm(forms.Form):
start_date = forms.CharField()
end_date = forms.CharField()
and here is views.py
def plot_data(request):
context={}
trackform = PickTrackForm()
context["trackform"]=trackform
if request.method == 'POST':
timeform = PickTimesForm(request.POST)
if timeform.is_valid():
target_directory= '/home/bitnami/htdocs/projects/laserviz/data/'
start_date = timeform.cleaned_data.get("start_date")
end_date = timeform.cleaned_data.get("end_date")
[data,lats,lons] = tf.getTracks(start_date,end_date,target_directory)
[fig_html, track_info]= tf.makeMap(lons,lats)
context["figure"]=fig_html
context["track_info"]=track_info
context["timeform"]=timeform
context["start_date"]=start_date
context["end_date"]=end_date
context["data"]=data
return render(request,'index.html',context)
else:
timeform = PickTimesForm()
context['timeform']=timeform
return render(request,'index.html',context)