Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Last active March 10, 2020 16:48
Show Gist options
  • Select an option

  • Save dineshsprabu/ce6cddfbd6422a1704de7c250b0b0ef0 to your computer and use it in GitHub Desktop.

Select an option

Save dineshsprabu/ce6cddfbd6422a1704de7c250b0b0ef0 to your computer and use it in GitHub Desktop.
[Python][Tornado] Get all form submitted arguments and convert to dict
class Handler(tornado.web.RequestHandler):
def args_to_dict(self):
""" This method converts request arguments to
usable dict
"""
params = self.request.arguments
for k,v in params.items():
params[k] = v[0].decode("utf-8")
return params
def post(self):
# This will return all arguments as dict.
self.request.arguments
# Decode the value of each key to str
# from byte.
self.request.arguments[key][0].decode('utf-8')
# Params as dict.
params_in_hash = self.args_to_dict()
@javadba

javadba commented Jan 29, 2020

Copy link
Copy Markdown

what version of Tornado? I just installed (2 yrs later) and there is no method args_to_dict() on the RequestHandler

@wildzyzop

Copy link
Copy Markdown

there is no method args_to_dict() on the RequestHandler

@javadba The method is defined in the user class Handler inherited from RequestHandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment