Answer the question
In order to leave comments, you need to log in
How to check for the identity of two fields without a POST request? Django
In short, after a thousand years, I again return to this issue. I haven't been able to solve it yet.
To do it the way I want - you need to fasten AJAX.
I don't want to do it and I don't know how.
What I want to do right now: so that this check is not carried out instantly, but when the button is pressed, which activates the POST request.
What I have: I have overridden the clean_filename methods:
def clean_password(self):
value_password = self.cleaned_data.get('password')
if len(str(self.cleaned_data['password'])) < 6:
raise forms.ValidationError({'password': ["Password must been more then 6 symbols"]})
elif len(str(self.cleaned_data['password'])) > 45:
raise forms.ValidationError({'password': ["Password must been less 45 symbols"]})
elif value_password is None:
raise forms.ValidationError({'password': ["Field of password can't are blank"]})
return value_password
def clean(self):
super(Form_registration, self).clean()
data = self.cleaned_data
if data["password"] != data["password2"]:
raise ValidationError({'password2': ["Password must been are equals"]})
return data
{{ form_registration.non_field_errors }}
#всякая ерундистика
<div class="fieldWrapper">
{{ form_registration.password }}
<label for="id_password"></label>
{{ form_registration.password.errors }}
</div>
<div class="fieldWrapper">
{{ form_registration.password2 }}
<label for="id_password2"></label>
{{ form_registration.password2.errors }}
</div>
class DivErrorList(ErrorList):
def __str__(self): # __unicode__ on Python 2
return self.as_divs()
def as_divs(self):
if not self:
return ''
return '<div class="errorlist">%s</div>' % ''.join(['<div class="error">%s</div>' % e for e in self])
def saves_data_user_on_registration (request):
c = {}
form_registration = Form_registration(request.POST, request.FILES, error_class=DivErrorList)
c['form_registration'] = form_registration
if request.method == 'POST':
c.update(csrf(request))
if form_registration.is_valid():
form_registration.save()
return render_to_response('see_you_later.html', c,
context_instance=RequestContext(request))
else:
print form_registration
return render_to_response('first_page.html', c,
context_instance=RequestContext(request))
Answer the question
In order to leave comments, you need to log in
use this lib https://github.com/agiliq/Django-parsley here and there is validation on the client and on the server.
Errors need to be sent to the template and output there and not through
print form_registration.errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question