Answer the question
In order to leave comments, you need to log in
Error codes in django.forms?
On validation errors, django.forms return text messages describing the error. For building a REST API, this is not very convenient, since you also need to return an error code. You have to store a dictionary like this:
message_codes = {<br>
'password': {<br>
'default': errors.InvalidPassword,<br>
'This field is required': errors.PasswordMissing,<br>
},<br>
'newPassword': {<br>
'default': errors.InvalidPassword,<br>
'This field is required': errors.PasswordMissing,<br>
},<br>
}<br>
Answer the question
In order to leave comments, you need to log in
Well, there’s probably no more truth here, because. only instances with text come from clean, and they are collected inside also with text into a dictionary by field names. This piece under the link as I understood, does the same (matches). In your clean (forms, fields, etc.) you can somehow return with the code and whatever you like, it's just not very clear at what level you have the REST API. If it is higher than the forms, then you won’t do it in any way, because. going inside the forms anyway in the dictionary. If it’s lower, well, then either your own validations, or + in addition, overlap the standard ones.
In general, they usually try to isolate the data processing logic into separate modules. And to build a REST API, they use special tools like tastypieapi.org or django-rest-framework.org .
You need to handle GET, PUT, UPDATE, DELETE, etc. How do you do it with forms?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question