Frage

My case is maybe silly and simple..but help me please :) I'm sending a parameter (single character) via android application using the GET request to a tornado server.. all what i need is tornado to resolve the parameter sent to it in order to compare it with a value.. i saw some documentation with examples using such as :

    def get(self):
     cmd = self.get_arguements(command,TRUE)
     if self.get_arguements == "a" :
     ...do something

any help please?

War es hilfreich?

Lösung

Let's modify the example code from tornadoweb.

    import tornado.ioloop
    import tornado.web

    class MainHandler(tornado.web.RequestHandler):
        def get(self):
            print("Hello!")  # Just so you see that the right handler is invoked
            # Lets get what's in the ?command=...
            cmd = self.get_argument("command", None)
            if cmd == 'd':
                print("You passed in the 'd' command")
            elif cmd == 'r':
                print("We got the r command!")
            else:
                print("Command unknown :(")

    application = tornado.web.Application([
        (r"/", MainHandler),
    ])

    if __name__ == "__main__":
        application.listen(80)
        tornado.ioloop.IOLoop.instance().start()

This assumes the request looks something like this:

GET /?command=d
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top