Created
December 6, 2011 19:59
-
-
Save saketkc/1439694 to your computer and use it in GitHub Desktop.
Prevent multiple form submission for Django Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Where is the 'sessionform' set in the session? Do you have to do that manually?