开发者

Stopping a request in Tornado

开发者 https://www.devze.com 2023-03-06 01:33 出处:网络
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

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 s开发者_开发技巧elf.redirect so print "User Is OK" is never called?


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

   print "User Is OK"


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


Just do a return, like this:

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

       print "User Is OK"
0

精彩评论

暂无评论...
验证码 换一张
取 消