。
これは私のアプリの構造です。
まずmain.py
:
import tornado.ioloop
import tornado.web
import views
class MainHandler(tornado.web.RequestHandler):
def get(self):
HL = {
'headlines': ['head1', 'head2', 'head3'],
}
self.render('tmpl.html', HL=HL)
if __name__ == "__main__":
application = tornado.web.Application([
(r"/", MainHandler),
], ui_modules=views)
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
次に、あなたのテンプレートtmpl.html
:あなたはすべてのあなたのUIモジュールを定義することができ
<html>
{% for headline in HL['headlines'] %}
{% module Headline(headline) %}
{% end %}
</ul>
</body>
</html>
最後に
、views.py
、:
from tornado.web import UIModule
class Headline(UIModule):
def render(self, name):
return '<h1>%s</h1>' % name
UI modules
は "のようなものです再利用可能なテンプレート "、tハットはパラメータを受け入れます。
ありがとうございました! - ちょうどあなたの反応を見ました。試してみる。 – idiotype
私は間違いをしているのか、それとも上のものを作っているのかは、トルネード3.1.1では分かりません。彼らはui_modulesは辞書でなければならないと言います。その場合は動作します。 – avi