Skip to content

Instantly share code, notes, and snippets.

@saketkc
Created December 6, 2011 19:59
Show Gist options
  • Save saketkc/1439694 to your computer and use it in GitHub Desktop.
Save saketkc/1439694 to your computer and use it in GitHub Desktop.
Prevent multiple form submission for Django Forms
import hashlib
def register(request):
if request.method == 'POST':
request_post = request.POST
registration_form = RegistrationFormUniqueEmail(request_post)
hashstring=hashlib.sha1(str(request.POST.get('csrf_token'))) ## This is going to be unique ! A unique has
if request.session.get('sesionform')!=hashstring:
if registration_form.is_valid():
username = registration_form.cleaned_data['username']
email = registration_form.cleaned_data['email']
password = registration_form.cleaned_data['password']
new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, "site")
registration_form = RegistrationFormUniqueEmail()
return render_to_response('registration/register.html', {'registration_form': registration_form,'messages': "An Email has been sent for your confirmation"})
else:
return render_to_response('registration/register.html', {'registration_form': registration_form,'messages':"Error"})
else:
return HttpRedirect("/register")
@sid24ss
Copy link

sid24ss commented Feb 24, 2014

Where is the 'sessionform' set in the session? Do you have to do that manually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment