Hello,
I’m trying to run the example but I get the following KeyError:
Traceback (most recent call last):
File "/home/yoel/Development/tryton/marketing/app/app.py", line 11, in <module>
User = tryton.pool.get('res.user')
File "/home/yoel/Development/tryton/marketing/venv/lib/python3.6/site-packages/trytond/pool.py", line 179, in get
return self._pool[self.database_name][type][name]
KeyError: 'res.user'
This is how looks my app.py file:
from flask import Flask
from flask_tryton import Tryton
app = Flask(__name__)
app.config['TRYTON_CONFIG'] = '/home/yoel/Development/tryton/5.0/full/conf/trytond.conf'
app.config['TRYTON_DATABASE'] = 'tryton_full_new'
app.config['TRYTON_USER'] = 1
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)
if __name__ == '__main__':
app.run(debug=True, port=5000)
Could anyone tell me how can I make it work? Thanks.
You need a working trytond server first. Flask_tryton it’s another interface for your existing trytond server (Like tryton client ). Did you check trytond.conf? Are you able to connect using tryton client on same server ?
Yes, I’m using virtualenv, I’ve moved the Flask script to the same virtualenv that uses Tryton, but I’m still getting the same KeyError that I posted at the beginning of this topic.
Is it imperative use the same virtualenv for Tryton and Flask?
Yes, you should run the same code so flask is able to load the Tryton modules.
Because you did not set up any trytond.conf file, so it’s using the default one which uses sqlite.
You should set the TRYTOND_CONFIG environment variable pointing to the route of your configuration file to use a diferent backend.