Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python tornado get request url

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 ?

like image 562
Lee_Prison Avatar asked May 19 '13 17:05

Lee_Prison


2 Answers

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

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(self.request.uri)
like image 127
stalk Avatar answered Oct 14 '22 21:10

stalk


I think what you're looking for is self.request.path. Look at the functions available for HTTPServerRequest.

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(self.request.path)
like image 37
Kemal Ahmed Avatar answered Oct 14 '22 21:10

Kemal Ahmed