0

この質問を編集して、小さな例を示しました。このデモ コードは、Introduction to tornado book からのもので、次のエラーが表示されます。

Traceback (most recent call last):
  File "demo.py", line 25, in <module>
    ui_modules={'Hello', HelloModule}
  File "/usr/local/lib/python2.7/dist-packages/tornado-3.1.1-py2.7.egg/tornado/web.py", line 1422, in __init__
    self._load_ui_modules(settings.get("ui_modules", {}))
  File "/usr/local/lib/python2.7/dist-packages/tornado-3.1.1-py2.7.egg/tornado/web.py", line 1545, in _load_ui_modules
    assert isinstance(modules, dict)
AssertionError

デモ.py

import tornado.web
import tornado.httpserver
import tornado.ioloop
import tornado.options 
import os.path
from tornado.options import define, options
define("port", default=8000, help="run on the given port", type=int)


class HelloHandler(tornado.web.RequestHandler):
    def get(self):
        self.render('hello.html')


class HelloModule(tornado.web.UIModule):
    def render(self):
        return '<h1>Hello, world!</h1>'

if __name__ == '__main__':
    tornado.options.parse_command_line()

    app = tornado.web.Application(
        handlers=[(r'/', HelloHandler)],
        template_path=os.path.join(os.path.dirname(__file__), 'templates'),
        ui_modules={'Hello', HelloModule}
    )
    server = tornado.httpserver.HTTPServer(app)
    server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

hello.html

<html>
<head><title>UI Module Example</title></head>
<body>
{% module Hello() %}
</body>
</html>
4

2 に答える 2

1

実際には、ここにある本の正誤表があります

于 2015-02-23T15:36:07.600 に答える