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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -