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 ='/foo?baz=3.14&spam=spam', data={'bar': 2718281828})
        assert json.loads( == {
            'baz': 3.14, 'bar': 2718281828, 'spam': 'spam'}

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

        r ='/echo', data={'msg': 'hello'})
        assert == 'hello'
File Type Py Version Uploaded on Size (md5) Source 2013-10-06 3KB
  • Downloads (All Versions):
  • 3 downloads in the last day
  • 54 downloads in the last week
  • 293 downloads in the last month