Code argument when raising validation errors

In the validation docs it talks about it being good practice to pass in a code argument when raising a ValidationError. Where do these codes come from? Is there a list of them? Should I just make up my own codes as what seems appropiate?

Yes, you make up your own codes. The codes provide a way for other modules to know what errors were thrown and possibly take direct action. You don’t want to rely only upon the text of the message because it could be translated into different languages or there might be variables put into the error text.

1 Like