[Answer]-Duplicate entry in database on refreshing the submitted form in django

1👍

If you really insist on using GET to submit which practically is not a good method. You should do a request redirect using HttpResponseRedirect from the server side which will remove the query string from the url . This way it wouldn’t resumit the form.

def show(request,post_id):
    try:
        p = post.objects.get(pk=post_id)
        c = comment.objects.filter(blog_id=p)
        if 'cbox' in request.GET:
            c = comment(text=request.GET['cbox'],name=request.GET['cname'],blog=p)
            c.save()
            #Do a redirect here 
            return HttpResponseRedirect("URL of the page you would like to redirect")
        c_list = comment.objects.filter(blog_id=p)   
    except  post.DoesNotExist:
        raise Http404
    return render_to_response('show.html',{'post':p,'c_list':c_list})

Leave a comment