skip to navigation
skip to content

Not Logged In

flask-args 0.3.0

auto type convertion for flask.request.form/args/values

import json

from flask import Flask, jsonify

from flask_args import args


app = Flask(__name__)
app.debug = True


@app.route('/foo', methods=['POST'])
@args('form', bar=int)
@args('args', baz=float, spam=str)
def foo(bar, baz, spam):
    return jsonify({'bar': bar, 'baz': baz, 'spam': spam})


@app.route('/echo', methods=['GET', 'POST'])
@args('values', msg=str)
def echo(msg):
    return msg

if __name__ == '__main__':
    with app.test_client() as client:
        r = client.post('/foo?baz=3.14&spam=spam', data={'bar': 2718281828})
        assert json.loads(r.data) == {
            'baz': 3.14, 'bar': 2718281828, 'spam': 'spam'}

        r = client.get('/echo?msg=hello')
        assert r.data == 'hello'

        r = client.post('/echo', data={'msg': 'hello'})
        assert r.data == 'hello'
 
File Type Py Version Uploaded on Size
flask-args-0.3.0.zip (md5) Source 2013-10-06 3KB
  • Downloads (All Versions):
  • 12 downloads in the last day
  • 37 downloads in the last week
  • 282 downloads in the last month