Iam using jquery AJAX request using post methid to send parameters to tornado server and did something like this:
$.ajax({
type: "POST",
url: "/leave_action?id=" + rowid.id + "&action=" + param,
dataType: "json",
async: false
})
But when I'm comparing using python, it is not working:
action = str(self.get_query_argument("action"))
print action #here am getting either approve or decline
if action == "approve":
print "approved"
elif action == "decline":
print "declined"
I tried with is also but no luck.
I also tried with:
action = self.get_query_argument("action")
a=action.encode('ascii','ignore')
but no use.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With