1
class LeaveFormHandler(BaseHandler):
  def post(self):
    #form submission code goes here
      #after this code i wanted to call post method of MyleavesHandler class

class MyleavesHandler(BaseHandler):
  def post(self):
        self.write(json.dumps(r))

after the form submission code in the above snippet, i wanted to call post method of MyleavesHandler class.. can anyone please help am a newbie

iam using tornado webserver with python

1 Answer 1

2

You can't call instance methods of another handler because you can't easily construct one, and even if you could, you need to ultimately call self.write() on the LeaveFormHandler, not the MyleavesHandler. You need to factor the logic you want to share out into a shareable location, either a common base class or a static function that takes a handler as an argument.

2
  • can you give me a code snippet suggesting the same.please dont mind as am novice to python and tornado Apr 8, 2014 at 12:15
  • 2
    def write_response(handler, r): handler.write(json.dumps(r)). Then in each post method, call write_response(self, r) Apr 8, 2014 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.