1π
β
In order to prevent duplicate form submission you should implement the
Post/Redirect/Get
Pattern
So if the form submission is valid and you performed all data manipulation redirect to the empty form page:
def post(request, slug):
user = get_object_or_404(User,username__iexact=request.user)
...
...
if comment_form.is_valid():
# do you data manipulation
...
# redirect to the empty form view
return HttpResponseRedirect('/url_of_empty_form/')
...
# this will only render if the form is not valid
return render(request, 'main/post.html', context_dict)
π€ilse2005
Source:stackexchange.com