跳转到主要内容

为Flask应用添加Tryton支持

项目描述

为Flask应用添加Tryton支持。

默认情况下,事务为只读,除非是PUT、POST、DELETE和PATCH请求方法。它还提供了两个路由转换器recordrecords

设置configure_jinja标志会在jinja模板中添加以下过滤器:numberformatdateformatcurrencyformattimedeltaformat。这些过滤器应用了与Tryton报告相同的格式。

概要

>>> from flask import Flask
>>> from flask_tryton import Tryton
>>> app = Flask(__name__)
>>> app.config['TRYTON_DATABASE'] = 'test'
>>> tryton = Tryton(app, configure_jinja=True)
>>> 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()

有三个配置选项可供选择

  • TRYTON_DATABASE:要连接的Tryton数据库。

  • TRYTON_USER:要使用的Tryton用户ID,默认为0(即根用户)。

  • TRYTON_CONFIG:可选的Tryton配置路径。

如需报告问题,请访问flask_tryton错误跟踪器

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

flask_tryton-0.12.0.tar.gz (19.4 kB 查看哈希值)

上传时间 源代码

构建分发

flask_tryton-0.12.0-py3-none-any.whl (17.1 kB 查看哈希值)

上传时间 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面