标签:des style blog http io ar os 使用 sp
请求处理程序和请求参数:
原创首发:http://www.cnblogs.com/zxlovenet/p/4128644.html
# code 1 class MainHandler(tornado.web.RequestHandler): def get(self): self.write("You requested the main page") class StoryHandler(tornado.web.RequestHandler): def get(self, story_id): self.write("You requested the story " + story_id) application = tornado.web.Application([ (r"/", MainHandler), (r"/story/([0-9]+)", StoryHandler), ])
application = tornado.wsgi.WSGIApplication([ (r"/([a-z]*)", ContentHandler), (r"/static/tornado-0.2.tar.gz", tornado.web.RedirectHandler, dict(url="http://github.com/downloads/facebook/tornado/tornado-0.2.tar.gz")), ], **settings)
class MainHandler(tornado.web.RequestHandler): def get(self): if not self.get_secure_cookie("mycookie"): self.set_secure_cookie("mycookie", "myvalue") self.write("Your cookie was not set yet!") else: self.write("Your cookie was set!") application = tornado.web.Application([ (r"/", MainHandler), ], cookie_secret="61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=")
class MainHandler(BaseHandler): @tornado.web.authenticated def get(self): name = tornado.escape.xhtml_escape(self.current_user) self.write("Hello, " + name) settings = { "cookie_secret": "61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", "login_url": "/login", } application = tornado.web.Application([ (r"/", MainHandler), (r"/login", LoginHandler), ], **settings)
"static_path": os.path.join(os.path.dirname(__file__), "static")
static_url()
函数会将相对地址转成一个类似于 /static/images/logo.png?v=aae54
的 URI,v 参数是 logo.png 文件的散列值, Tornado 服务器会把它发给浏览器,并以此为依据让浏览器对相关内容做永久缓存。class HomeHandler(tornado.web.RequestHandler): def get(self): entries = self.db.query("SELECT * FROM entries ORDER BY date DESC") self.render("home.html", entries=entries) class EntryHandler(tornado.web.RequestHandler): def get(self, entry_id): entry = self.db.get("SELECT * FROM entries WHERE id = %s", entry_id) if not entry: raise tornado.web.HTTPError(404) self.render("entry.html", entry=entry) settings = { "ui_modules": uimodules, } application = tornado.web.Application([ (r"/", HomeHandler), (r"/entry/([0-9]+)", EntryHandler), ], **settings) {% module Entry(entry, show_comments=True) %}
标签:des style blog http io ar os 使用 sp
原文地址:http://www.cnblogs.com/zxlovenet/p/4128644.html