-
-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now accepting as the required message anything that the ValidationErr…
…or constructor takes
- Loading branch information
Showing
3 changed files
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -236,18 +236,23 @@ Required Fields | |
|
||
You can make a field required by passing ``required=True``. An error will be stored if the the value is missing from the input to :meth:`Schema.load`. | ||
|
||
Alternatively, you can provide a custom error message by passing ``required='My custom message'`` (and the required validation will be enabled as if ``required=True``) | ||
Alternatively, you can provide a custom error message by passing ``required='My custom message'`` (and the required validation will be enabled when ``if required`` succeeds). | ||
Dictionaries or lists are also accepted as the custom error message, in case you want to provide more information with the error. | ||
|
||
.. code-block:: python | ||
:emphasize-lines: 2,6 | ||
class UserSchema(Schema): | ||
name = fields.String(required=True) | ||
age = fields.Integer(required='Age is required.') | ||
city = fields.String(required={'message': 'City required', 'code': 400}) | ||
email = fields.Email() | ||
data, errors = UserSchema().load({'email': '[email protected]'}) | ||
errors # {'name': ['Missing data for required field.'], 'age': ['Age is required.']} | ||
errors | ||
# {'name': ['Missing data for required field.'], | ||
# 'age': ['Age is required.'], | ||
# 'city': {'message': 'City required', 'code': 400}} | ||
Schema.validate | ||
+++++++++++++++ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters