Giter VIP home page Giter VIP logo

flask_voluptuous's Introduction

flask_voluptuous

A simple flask extension for data validation with Voluptuous

Usage

from flask import Flask
from flask_voluptuous import expect, Schema, Required

app = Flask(__name__)

@app.route('/')
@expect(Schema({
    Required('name'): str
  }), 'args')
def index(args):
    return 'name: {}'.format(args['name'])

if __name__ == '__main__':
    app.run(debug=True)

The / route requires a name param in the request arguments. This data are accesible throw the args arguments passed to the function.

If the data is not submitted, we get an 406 error:

$ http http://127.0.0.1:5000/?other=ludusrusso
HTTP/1.0 406 NOT ACCEPTABLE
Content-Length: 160
Content-Type: text/html
Date: Mon, 02 Oct 2017 10:44:33 GMT
Server: Werkzeug/0.12.2 Python/3.6.1

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>406 Not Acceptable</title>
<h1>Not Acceptable</h1>
<p>extra keys not allowed @ data['other']</p>
$ http http://127.0.0.1:5000/?name=ludusrusso
HTTP/1.0 200 OK
Content-Length: 16
Content-Type: text/html; charset=utf-8
Date: Mon, 02 Oct 2017 10:42:18 GMT
Server: Werkzeug/0.12.2 Python/3.6.1

name: ludusrusso

flask_voluptuous's People

Contributors

ludusrusso avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.