Hello, first of all, happy holidays, the problem I have is the following…
I have this code in a python file called app.py
from flask import Flask, render_template, request, redirect, url_for
from flask_tryton import Tryton
import taller
app = Flask(__name__)
# conectarla a la bbdd
app.config['TRYTON_DATABASE'] = 'cars_db'
tryton = Tryton(app, configure_jinja=True)
Marca = tryton.pool.get('taller.marca')
Modelo = tryton.pool.get('taller.modelo')
Coche = tryton.pool.get('taller.coche')
Party = tryton.pool.get('party.party')
@app.route('/')
@tryton.transaction()
def lista_coches():
marcas = Marca.search([]) # para que devuelva todos los registrospi
return render_template('marca.html', marca=marcas)
The first thing I do is
export FLASK_APP=app.py
Once done, I put it in development
export FLASK_ENV=development
and when I run
flask run
it gives me this error
osboxes@osboxes:~/prueba/taller$ flask run
Traceback (most recent call last):
File "/home/osboxes/.local/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/osboxes/.local/lib/python3.10/site-packages/flask/cli.py", line 1064, in main
cli.main()
File "/home/osboxes/.local/lib/python3.10/site-packages/click/core.py", line 1078, in main
rv = self.invoke(ctx)
File "/home/osboxes/.local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/osboxes/.local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/osboxes/.local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/osboxes/.local/lib/python3.10/site-packages/click/decorators.py", line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/home/osboxes/.local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
return __callback(*args, **kwargs)
File "/home/osboxes/.local/lib/python3.10/site-packages/flask/cli.py", line 912, in run_command
raise e from None
File "/home/osboxes/.local/lib/python3.10/site-packages/flask/cli.py", line 898, in run_command
app = info.load_app()
File "/home/osboxes/.local/lib/python3.10/site-packages/flask/cli.py", line 313, in load_app
app = locate_app(import_name, None, raise_if_not_found=False)
File "/home/osboxes/.local/lib/python3.10/site-packages/flask/cli.py", line 219, in locate_app
__import__(module_name)
File "/home/osboxes/prueba/taller/app.py", line 11, in <module>
tryton = Tryton(app, configure_jinja=True)
File "/home/osboxes/.local/lib/python3.10/site-packages/flask_tryton.py", line 51, in __init__
self.init_app(app)
File "/home/osboxes/.local/lib/python3.10/site-packages/flask_tryton.py", line 66, in init_app
with Transaction().start(database, user, readonly=True):
File "/home/osboxes/.local/lib/python3.10/site-packages/trytond/transaction.py", line 218, in start
self.stop(False)
File "/home/osboxes/.local/lib/python3.10/site-packages/trytond/transaction.py", line 241, in stop
self.database.put_connection(
AttributeError: 'NoneType' object has no attribute 'put_connection'
I have tried connecting to the database and I have made a couple of SQL queries and it works, but I don’t know what I am failing here.
ok, I just saw what my mistake was, I have to load the address where my trytond.conf file is located
export TRYTON_CONFIG=/home/osboxes/trytond.conf
And now it works.