Created
August 10, 2012 04:47
-
-
Save cjgiridhar/3311136 to your computer and use it in GitHub Desktop.
Tornado - Template - Template() and Loader()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html>{{ name }}</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
from tornado.template import Template | |
from tornado.template import Loader | |
class Article(tornado.web.RequestHandler): | |
def get(self): | |
## Works with Template method of tornado.template | |
t = Template("<html>{{ name }}</html>") | |
self.write(t.generate(name="John")) | |
## Works with Loader method of tornado.template | |
loader = Loader(".") | |
self.write(loader.load("template.html").generate(name="John")) | |
application = tornado.web.Application([ | |
(r"/articles", Article), | |
],debug=True) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment