Search code examples
pythontornadoweb.py

Stopping a request in Tornado


I have a method for signing up a user, basically if the user fails validation I want the request to stop processing so the user isn't signed up.

def post(self):
       #[...]
       if isvalid(username) == False:
           print "Invalid Username"
           self.redirect("/badusername")

       print "User Is OK"

If I enter a valid username, 'User Is OK' is printed to the console and everything is dandy, but if I use an invalid username, 'Invalid Username' AND 'User Is OK' is printed to the console, the page re- directs correctly though. How do I stop the request after self.redirect so print "User Is OK" is never called?


Solution

  • def post(self):
       #[...]
       if isvalid(username) == False:
           print "Invalid Username"
           self.redirect("/badusername")
           return
    
       print "User Is OK"