如何访问 UI 模块中的数据库连接?我在 Tornado 中使用 MySQL 的内置包装器。
我的应用程序完全相似this
最佳答案
只映射模块类,不要使用单独的uimodule.py。 像这样:
class EntryModule(tornado.web.UIModule):
def render(self, entry):
return self.render_string('modules-entry.html', entry=entry)
settings = {
"login_url": "/login",
ui_modules={"Entry": EntryModule},
}
application = tornado.web.Application([
(r"/", HomeHandler),
(r"/entry/([0-9]+)", EntryHandler),
], **settings)
注意:ui_modules={"Entry": EntryModule}
关于python - 从 Tornado 中的 UI 模块访问数据库连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9721146/