There is some points you better to know ! The Tornado is a MVC based framework that let you have a lot of things in your hand.
So, you can set URL pattern instead using query string. that's mean you don't need to get value with self.get_query_argument()
or self.get_argument()
.
For URL:
application = tornado.web.Application([
(r'^(?i)/leave_action/([\w+^/])/([\w+^/])[/]?$', YourLeaveActionHandler)
], **settings)
or even:
application = tornado.web.Application([
(r'/leave_action/(id)/(approve|decline)', YourLeaveActionHandler, None, "this_url_name")
], **settings)
The second URL pattern is better a bit. because we emphasize expressly the first group should be id
and the second group should approve
OR decline
.
And in your handler:
class YourLeaveActionHandler(tornado.web.RequestHandler):
def get(self, id, action):
print id
print action
def post(self, id, action):
print id
print action
if action == "approve":
print "approved"
elif action == "decline":
print "declined"
In your handler , the action
should be approve
OR decline
and anything else expect these not accepted in this handler. So you can easily compare the action value.
- And you should note this,sometimes when you using POST method, the query string maybe ignored by tornado.