-
-
Save jdiego/2dae7d35e1dd7c3ebf0c560247d1e51d to your computer and use it in GitHub Desktop.
Prevent multiple form submission for Django Forms
This file contains hidden or 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