Umut KIRGÖZ
Umut KIRGÖZ

Reputation: 2123

Get dict from query string/post data in Tornado web server?

Maybe I am missing something, this should be very easy thing if I code PHP, but weird I cannot handle this basic thing in python tornado web server.

Tornado web server gets a request like this :

http://example.com/?a[x]=1&a[y]=2&a[z]=3&b=4

I need to get a as a dict in python

In Tornado:

class BaseHandler(tornado.web.RequestHandler):

    def get(self):
        print self.get_argument('a') #failed 
        print self.get_arguments('a') #failed 

Any ready to use solution to this problem, or have I to code my custom method for parsing this from self.request.query_arguments

Any suggestions?

Upvotes: 0

Views: 1429

Answers (2)

Bob
Bob

Reputation: 113

self.get_argument('a[x]')

But never seen any one who write an url like this

You may need json dump string and warp it within http body

Upvotes: 0

Ben Darnell
Ben Darnell

Reputation: 22134

PHP (and I think Ruby) may treat brackets in argument names specially, but this is not standard. As far as python and tornado are concerned, these are simply arguments named a[x], a[y], etc. To reassemble them into a dictionary you'll need to parse them out of self.request.query_arguments.

Upvotes: 2

Related Questions