python - How can I use rest serializer.ValidationError in django forms? -
i new django , rest_framework. have password complexity rules script 'new user' page.
if complexity requirements satisfy needs, return true. else raises serialiser.validationerror
.
i duplicated django's forget password mechanism apply password rules. when raises error, application crashes below.
exception type: validationerror exception value: [u"the 2 password fields didn't match."]
is possible use serializer errors form errors {{ form.new_password1.errors }}
?
it's possible write own custom exception handler return error in preferred format.
the official documentation, @ bottom of page, says:
the validationerror class should used serializer , field validation, , validator classes. raised when calling serializer.is_valid raise_exception keyword argument: generic views use raise_exception=true flag, means can override style of validation error responses globally in api. so, use custom exception handler, described above.
serializer.is_valid(raise_exception=true)
by default exception results in response http status code "400 bad request"
please read here create custom handler.
Comments
Post a Comment