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"
精彩评论