Comments (8)
Thanks @dwieeb!
Another way to get the same functionality as use
is through a custom field.
class Use(fields.Field):
def __init__(self, func, child=None, **kwargs):
super().__init__(**kwargs)
self.func = func
self.child = child
def _deserialize(self, value, attr, data):
if self.child:
value = self.child.deserialize(value, attr, data)
return self.func(value)
@use_args({
'foo': Use(lambda v: v.upper(), fields.Str())
})
def myview(args):
#...
from webargs.
Interesting. Perhaps this could exist in the webargs codebase as fields.Lambda
or fields.Alter
or something?
from webargs.
Perhaps in the future. In the interest of keeping the core small, I'm going to hold off on adding this to the code base for now.
from webargs.
👍 I agree.
Besides, I think I would actually prefer the marshmallow solution, as it allows access to other fields and does not require custom fields.
Thanks for webargs. With the marshmallow integration it's the best solution out there even without being "stable"... And I've used pretty much everything out there for flask, including rolling my own.
from webargs.
Thanks for the encouraging words!
from webargs.
I've moved this to the Wiki here: https://github.com/sloria/webargs/wiki/Recipes . Thanks again @dwieeb !
from webargs.
You didn't need to do that; I'm not sure if a migration guide of a lesser used feature from an alpha version is helpful to people, especially as the 1.0 code base matures.
What's more important is that the documentation somehow shows the pre-processing and post-processing of schemas. Currently, there's just a link to the marshmallow api in the "marshmallow integration" section. People coming into webargs with no prior marshmallow experience may be looking in the docs for how to process values before they enter their route functions. Right now, it looks as if webargs doesn't have this.
I could get around to writing up something for the docs if I find time.
from webargs.
I agree; I think it would be useful to have some documentation for pre- and post-processing behavior. I would certainly welcome a PR.
from webargs.
Related Issues (20)
- potential documentation issue in quickstart/error-handling HOT 3
- Parse a schema that contains both file and form data HOT 2
- How to strip empty strings from list of strings in args using DjangoParser? HOT 3
- Tags cleanup HOT 2
- How to use partial loading with nested field HOT 2
- When setting location to `files`, custom field's `_deserialize` and `_validated` methods were not called HOT 7
- aiohttp. body argument is deprecated for http web exceptions HOT 1
- Update minimum supported versions of frameworks in next major release HOT 1
- Release version 8.2.0 HOT 4
- [Question] how to use this with line item like data? HOT 2
- Is there possible add Quixote web framework support HOT 2
- [Question] How to set up the Schema that will validate against a list of allowed enum values? HOT 1
- Dealing with empty values in `DelimitedFieldMixin` HOT 2
- Being able to handle ValidationError in Flask view methods without custom error handler HOT 4
- webargs.core.Parser should describe default for unknown either as marshmallow.EXCLUDE or "exclude" HOT 1
- RFC: support passing the whole parsed arguments as a keyword argument HOT 10
- Please consider using Mapping instead of Dict in ArgsMap to avoid type checker errors HOT 7
- Parse schema without using decorators HOT 1
- How to handle JSON data always nested / wrapped in a "body" object HOT 9
- Webargs 8 Question: Getting request data from 'data' instead of 'json'? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webargs.