python tornado get request url

Lee_Prison picture Lee_Prison · May 19, 2013 · Viewed 25.8k times · Source

Here is my code:

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(self.request.url)

def main():
    settings = {"template_path": "html","static_path": "static"}
    tornado.options.parse_command_line()
    application = tornado.web.Application([
       (r"/story/page1", MainHandler),
        ],**settings)

I want to get the string "/story/page1". how ?

Answer

stalk picture stalk · May 19, 2013

You can get current url inside RequestHandler using self.request.uri:

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(self.request.uri)