Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pedro-psb/pydantic-flask-form-handler
Helper classes to cut boilerplate on flask/pydantic form and file handling.
https://github.com/pedro-psb/pydantic-flask-form-handler
Last synced: 12 days ago
JSON representation
Helper classes to cut boilerplate on flask/pydantic form and file handling.
- Host: GitHub
- URL: https://github.com/pedro-psb/pydantic-flask-form-handler
- Owner: pedro-psb
- Created: 2022-08-12T14:15:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-12T14:49:19.000Z (over 2 years ago)
- Last Synced: 2024-11-23T09:43:26.031Z (2 months ago)
- Language: Python
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pydantic/Flask Form Handler
## Overview
Helper classes to cut boilerplate on pydantic/flask form and file handling.
The classes `FormHandler` and `FormWithFileHandler` get a flask request and a pydantic
Form Model as parameters. The return is either the validated form data or the errors,
which can have a custom format. By default they are shown per field (which differs form pydantic default).In the case of files, it handles the file exceptions alongside pydantic validation errors.
```python
try:
form_data = FormWithFileHandler(
request=request, FormModel=NameForm
).valid_form
print(form_data)
except FormError as e:
print(e.errors)
return redirect(url_for("upload_file_with_form"))
```## Observations
When `request.form` or `request.files` is accessed, the app raises `werkzeug.exceptions.RequestEntityTooLarge`.
So, if the file is too big, the rest of the form won't be validated.## TODO
* Write tests
* Feature: allow server-side data injection on the `request.form` data.
* Refactor types and fix linting errors
* Make it an installable package/plugin/blueprint