Skip to content

Instantly share code, notes, and snippets.

@jdiego
Forked from saketkc/view.py
Created March 11, 2017 00:47
Show Gist options
  • Save jdiego/2dae7d35e1dd7c3ebf0c560247d1e51d to your computer and use it in GitHub Desktop.
Save jdiego/2dae7d35e1dd7c3ebf0c560247d1e51d 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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment