I am running a tornado webserver. Also, I have a flask-based an “API”-like web app.
I want to switch from flask to the tornado as well.
Tornado — is the same as Django but much faster, simpler, and more straightforward.
So I have:
# __init__.py
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.options import define, options
from tornado.web import Application
from my_api.views import APIendpoint ## here are my views.py
import os
########### WEB SERVER INITIALIZATION #############
define('port', default=8888, help='port to listen on')
PATH = os.path.dirname(os.path.realpath(__file__))
settings = {'debug': True,
'static_path': os.path.join(PATH, 'static')}
## here I set the routes — what classes will be called
handlers = [
# ('/', HelloWorld),
(r'/api/v2/(.*)', APIendpoit),
]
engine = ?????? # here I am looking for a DB engine from Tryton
class Config(object):
DEBUG = False
TESTING = False
CSRF_ENABLED = True
TRYTON_DATABASE = 'my_tryton_database' # Data base I use in Tryton
SECRET_KEY = '<TOP SECRET KEY>'
DATABASE_URI = os.environ['DATABASE_URL'] # postgres driver
################ Start Server ###############
def main():
"""Construct and serve the tornado application."""
app = Application(handlers=handlers,
session_factory=engine,
**settings)
http_server = HTTPServer(app)
http_server.listen(options.port)
logger.info('Now listening on http://localhost:%i' % options.port)
IOLoop.current().start()
I cannot understand what I need to pass to views.py to have an access to all features of Tryton. In Flask I simply used the flask_tryton module:
my_beloved_tryton = Tryton(app, **somekwargs)
and happily could do almost anything I want.
But not here. I cannot understand how to get access to all these my model classes with all methods in them from the tornado server.
views.py
consists of classes that respond to web requests but what I need to import to have the total access to DB like in SQLAlchemy?