I'm using Flask with flask-restful and webargs (which uses Marshmallow as its backend). Currently I'm able to pull in fields I want with this:
class AddGroup(Resource):
args = {
'name': fields.Str(missing=None),
'phone': fields.Str(missing=None),
}
@use_args(args)
def get(self, args):
name = args['name'].strip()
# ... some GET-related code ...
@use_args(args)
def post(self, args):
name = args['name'].strip()
# ... some POST-related code ...
So far so good. But what I'd really like to do is make sure that args['name']
comes into the various methods ("post", "get", etc.) with whitespace already stripped, so I don't have to process each variable manually each time. (stripping whitespace is just an example - it may be some other simple or complex transformation)
Is there a way (either by overriding the String field, defining my own field, or whatever) that will allow the args
to be pre-processed before they arrive in the class methods?