I am facing one weird issue while using Django. I can see two entry of the video I am submitting in the database as the page where I am submitting the form refreshes automatically after submission (that is okay to refresh, as I can see the updated results in the table).
But the problem is while refreshing it resubmits the form. And if I manually refresh the page also it keeps submitting new videos. After doing some research I've found articles which leads to the problem in views.py in the application.
There is a similar question as well but the way they did I am not sure how to integrate with my view as I am returning some args to the page too. (Reference article: django form resubmitted upon refresh)
Below is the code which I already understand less.
# Uploading videos form
if not request.method == "POST":
f = UploadForm() # Send empty form if not a POST method
args = {"profile_data": profile_data, "video_data": video_data, "form": f}
return render(request, "home.html", args)
f = UploadForm(request.POST, request.FILES) # This line is to upload the actual user's content.
if not f.is_valid(): # Q: Why do we need to check this? And if we do then is the right place and way to do it?
args = {"profile_data": profile_data, "video_data": video_data}
return render(request, "home.html", args)
process_and_upload_video(request)
args = {"profile_data": profile_data, "video_data": video_data}
return render(request, "home.html", args)