https://github.com/simpleapples/flask-wtf-decorators
Using decorators to validate form.
https://github.com/simpleapples/flask-wtf-decorators
flask flask-extensions python
Last synced: about 1 month ago
JSON representation
Using decorators to validate form.
- Host: GitHub
- URL: https://github.com/simpleapples/flask-wtf-decorators
- Owner: simpleapples
- License: mit
- Created: 2018-04-24T09:23:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T03:04:42.000Z (about 8 years ago)
- Last Synced: 2025-08-25T09:36:18.979Z (9 months ago)
- Topics: flask, flask-extensions, python
- Language: Python
- Homepage: https://pypi.org/project/Flask-WTF-Decorators/
- Size: 11.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Flask-WTF-Decorators [](https://travis-ci.org/simpleapples/flask-wtf-decorators)
Using decorators to validate form.
# Installation
Using pip
`pip install flask-wtf-decorators`
Using Pipenv
`pipenv install flask-wtf-decorators`
# Usage
Flask-WTF-Decorators is easy to use. You can define a view that requires validation.
```python
from flask-wtf-decorators import FormValidator
form_validator = FormValidator()
@form_validator.validate_form(TestForm)
@app.route('/', methods=['GET', 'POST'])
def index(form):
pass
```
You can tell Flask-WTF-Decorators what to do when a form is illegal. To do this you should provide a callback for `error_handler`.
```python
@form_validator.error_handler
def error_handler(errors):
return jsonify({'errors': errors}), 400
```
# Test
`python -m unittest discover -s tests`
# Contributing
Please submit a pull request to contribute.
# License
This project is licensed under the MIT License.