@@ -151,30 +151,24 @@ Default `unknown`
151151+++++++++++++++++
152152
153153By default, webargs will pass `unknown=marshmallow.EXCLUDE ` except when the
154- location is `json `, `form `, or `json_or_form `. In those cases, it uses
155- `unknown=marshmallow.RAISE ` instead.
154+ location is `json `, `form `, ` json_or_form `, ` path `, or `path `. In those cases,
155+ it uses `unknown=marshmallow.RAISE ` instead.
156156
157- You can change these defaults by overriding `DEFAULT_UNKNOWN_BY_LOCATION ` and
158- `DEFAULT_UNKNOWN `. The first is a mapping of locations to values to pass, and
159- the second is the fallback value used if the location is not included in the
160- map.
161-
162- You can also define a default at parser instantiation, which will take
163- precedence over these defaults.
157+ You can change these defaults by overriding `DEFAULT_UNKNOWN_BY_LOCATION `.
158+ This is a mapping of locations to values to pass.
164159
165160For example,
166161
167162.. code-block :: python
168163
169164 from flask import Flask
170- from marshmallow import EXCLUDE , INCLUDE , fields
165+ from marshmallow import EXCLUDE , fields
171166 from webargs.flaskparser import FlaskParser
172167
173168 app = Flask(__name__ )
174169
175170
176171 class Parser (FlaskParser ):
177- DEFAULT_UNKNOWN = INCLUDE
178172 DEFAULT_UNKNOWN_BY_LOCATION = {" query" : EXCLUDE }
179173
180174
@@ -190,14 +184,30 @@ For example,
190184
191185
192186 # location is "json", which is not in DEFAULT_UNKNOWN_BY_LOCATION,
193- # so the parser's default value, `INCLUDE`, will be used
187+ # so no value will be passed for `unknown`
188+ @app.route (" /" , methods = [" POST" ])
189+ @parser.use_args ({" foo" : fields.Int(), " bar" : fields.Int()}, location = " json" )
190+ def post (self , args ):
191+ return f " foo x bar = { args[' foo' ] * args[' bar' ]} "
192+
193+
194+ You can also define a default at parser instantiation, which will take
195+ precedence over these defaults, as in
196+
197+ .. code-block :: python
198+
199+ from marshmallow import INCLUDE
200+
201+ parser = Parser(unknown = INCLUDE )
202+
203+ # because `unknown` is set on the parser, `DEFAULT_UNKNOWN_BY_LOCATION` has
204+ # effect and `INCLUDE` will always be used
194205 @app.route (" /" , methods = [" POST" ])
195206 @parser.use_args ({" foo" : fields.Int(), " bar" : fields.Int()}, location = " json" )
196207 def post (self , args ):
197208 unexpected_args = [k for k in args.keys() if k not in (" foo" , " bar" )]
198209 return f " foo x bar = { args[' foo' ] * args[' bar' ]} ; unexpected args= { unexpected_args} "
199210
200-
201211 Using Schema-Specfied `unknown `
202212+++++++++++++++++++++++++++++++
203213
@@ -230,9 +240,8 @@ If you wish to use the value of `unknown` specified by a schema, simply pass
230240 return f " area = { args[' length' ] * args[' width' ]} "
231241
232242
233- You can also set ``unknown=None `` when instantiating a parser, or set
234- ``DEFAULT_UNKNOWN = None `` to make this behavior the default for a parser
235- class.
243+ You can also set ``unknown=None `` when instantiating a parser to make this
244+ behavior the default for a parser.
236245
237246
238247When to avoid `use_kwargs `
0 commit comments