Skip to content

Commit 8838ea1

Browse files
Fix outdated docs (#1018)
* Fix outdated docs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 740ec6f commit 8838ea1

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ Contributors (chronological)
5959
* Anton Ostapenko `@AVOstap <https://github.com/AVOstap>`_
6060
* Tumuer `@un4gt <https://github.com/un4gt>`_
6161
* Marat Sharafutdinov `@decaz <https://github.com/decaz>`_
62+
* Felix Engelmann `@dorthrithil <https://github.com/dorthrithil>`_

docs/quickstart.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ Arguments are specified as a dictionary of name -> :class:`Field <marshmallow.fi
88

99
.. code-block:: python
1010
11-
from webargs import fields, validate
11+
from webargs import fields, validate, ValidationError
12+
13+
14+
def validate_password(password):
15+
if len(password) < 6:
16+
raise ValidationError("Password must be at least 6 characters long")
17+
1218
1319
user_args = {
1420
# Required arguments
1521
"username": fields.Str(required=True),
1622
# Validation
17-
"password": fields.Str(validate=lambda p: len(p) >= 6),
23+
"password": fields.Str(validate=validate_password),
1824
# OR use marshmallow's built-in validators
1925
"password": fields.Str(validate=validate.Length(min=6)),
2026
# Default value when argument is missing
@@ -122,9 +128,15 @@ Each :class:`Field <marshmallow.fields.Field>` object can be validated individua
122128

123129
.. code-block:: python
124130
125-
from webargs import fields
131+
from webargs import fields, ValidationError
132+
133+
134+
def is_positive(val):
135+
if val <= 0:
136+
raise ValidationError("Value must be positive")
137+
126138
127-
args = {"age": fields.Int(validate=lambda val: val > 0)}
139+
args = {"age": fields.Int(validate=is_positive)}
128140
129141
The validator must raise a :exc:`ValidationError <webargs.core.ValidationError>` for validation failures.
130142

0 commit comments

Comments
 (0)