Flask Tryton Module

flask_tryton

Flask-Tryton adds Tryton support to Flask application.
By default transactions are readonly except for PUT, POST, DELETE and PATCH request methods. It provides also 2 routing converters record and records.

>>> from flask import Flask
>>> from flask_tryton import Tryton
>>> app = Flask(__name__)
>>> app.config['TRYTON_DATABASE'] = 'test'
>>> tryton = Tryton(app)
>>> User = tryton.pool.get('res.user')
>>> @tryton.default_context
... def default_context():
...     return User.get_preferences(context_only=True)
>>> @app.route('/')
... @tryton.transaction()
... def hello():
...     user, = User.search([('login', '=', 'admin')])
...     return '%s, Hello World!' % user.name
>>> @app.route('/user/<record("res.user"):user>')
... @tryton.transaction()
... def user(user):
...     return user.name
>>> @app.route('/users/<records("res.user"):users>')
... @tryton.transaction()
... def users(users):
...     return ', '.join(u.name for u in users)
>>> app.run()
4 Likes

3 posts were split to a new topic: KeyError on starting flask with Tryton