Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
86 lines (60 sloc) 2.46 KB

Framework-specific instructions

Django Rest Framework

Django Rest Framework works straight out of the box. Simply add :func:`@qval() <qval.qval.qval>` to your views or use :func:`validate() <qval.qval.validate>` inside.

Django

For Django without DRF you may need to add exception handler to settings.MIDDLEWARE. Qval attempts to do it automatically if DJANO_SETTINGS_MODULE is set. Otherwise you'll see the following message:

WARNING:root:Unable to add APIException middleware to the MIDDLEWARE list. Django does not
support APIException handling without DRF integration. Define DJANGO_SETTINGS_MODULE or
add 'qval.framework_integration.HandleAPIExceptionDjango' to the MIDDLEWARE list.

Take a look at the plain Django example here.

Flask

If you are using Flask, you will need to setup exception handlers:

from flask import Flask
from qval.framework_integration import setup_flask_error_handlers
...
app = Flask(__name__)
setup_flask_error_handlers(app)

Since request in Flask is a global object, you may want to curry :func:`@qval() <qval.qval.qval>` before usage:

from flask import request
from qval import qval_curry

# Firstly, curry `qval()`
qval = qval_curry(request)
...

# Then use it as a decorator.
# Note: you view now must accept request as first argument
@app.route(...)
@qval(...)
def view(request, params):
...

Check out the full Flask example. You can run the example using the command below:

$ PYTHONPATH=. FLASK_APP=examples/flask-example.py flask run

Falcon

Similarly to Flask, with Falcon you will need to setup error handlers:

import falcon
from qval.framework_integration import setup_falcon_error_handlers
...
app = falcon.API()
setup_falcon_error_handlers(app)

Full Falcon example can be found in the github repository.

Use the following command to run the app:

$ PYTHONPATH=. python examples/falcon-example.py
You can’t perform that action at this time.