Tornado Url Not Match with ? ("Interrogation") Sign
Question: I'm using tornado to create a web service. I learn many ways to handle URLs
but i can't find a way to handle this URLS:

> Main-Dns:xxxx(port)/{System}(this is static)/{word}?q={word}

My code:

    
    
     import tornado.ioloop 
     import tornado.web
     import psycopg2
     import json
     import collections
     import datetime
     import decimal
    
    
     application = tornado.web.Application([
    
     (r"/system/(\w+)[?][q]=[\w+]",MainHandler),
    
     ])
    
     if __name__ == "__main__":
         application.listen(8888)
         tornado.ioloop.IOLoop.instance().start()
    

I tried many regex only when i erase the '?' it works

for example for this URLs get the uri:

    
    
    uri:/system/4?q=
    handler:r"/system/(\d)[?]q=",MainHandler
    
    uri:/system/word_word?q=
    handler:r"/system/(\w+)[?][q]=",MainHandler
    

The parameter is optional i only put the "()" to test sending parameter.

I used Python regex tester web, and find that i worked but in Tornado i think
it's not the same thing.

Thanks in advance.

Edit: more examples

    
    
       Handle:/system/(\w+)[?]q=(\w+)
       URL examples : /system/(any_word)?q=(any_word) like
                      /system/word_word?q=word
                      /system/wo5d_w5rd?q=w5ord    
    

Edit: This is the console output:

    
    
                 WARNING:tornado.access:404  GET/system/test?q=test
    

I can do without the '?' but i need to do it with the '?'.

Edit: With method get_argument(), it's something like this posible:

    
    
           Uri:/system/word?{last_name='Jackson_Smith'}  
           to get this parameters: "word" , "last_name" , "'Jackson_Smith'"
    


Answer: You don't want to try to capture the "?q=.." in the regular expression. You
capture that in the `RequestHandler` itself, using the `get_argument` method.

Here's a small example that I think captures what you're trying to do:

    
    
    #!/usr/bin/python
    
    import tornado.ioloop
    import tornado.web
    
    class MainHandler(tornado.web.RequestHandler):
        def get(self, word=None):
            self.write("word is %s\n" % word)
            self.write("uri is %s\n" % self.request.uri)
            self.write("q is %s\n" % self.get_argument("q"))
    
    
    application = tornado.web.Application([
    
    (r"/system/(.+)",MainHandler),
    
    ])
    
    if __name__ == "__main__":
        application.listen(8888)
        tornado.ioloop.IOLoop.instance().start()
    

Here's sample output:

    
    
    dan@dan:~$ curl localhost:8888/system/4?q=44d
    word is 4
    uri is /system/4?q=44d
    q is 44d
    dan@dan:~$ curl localhost:8888/system/word_word?q=word
    word is word_word
    uri is /system/word_word?q=word
    q is word
    dan@dan:~$ curl localhost:8888/system/wo5d_w5rd?q=w5ord
    word is wo5d_w5rd
    uri is /system/wo5d_w5rd?q=w5ord
    q is w5ord
    

