简体   繁体   中英

What is wrong with this redirect? (Google App Engine - Python)

In SubmitHandler I get the submitted url :

    url = self.request.get("url").rstrip().lstrip()

and check if its length is zero and if it is zero i redirect to /urlparseerror :

    if len(url) == 0:
        logging.info("""***len(url) is --zero--: %s***""" % len(url))
        self.redirect("/urlparseerror")

but for some reason the redirect is not executed. According to logging.info len(url) is zero:

***len(url) is --zero--: 0***

What am I doing wrong?

redirect() will not end the execution of the rest of your code. So if after the snippet you have posted, your code goes on to return some other kind of response your redirect will be ignored. If this is the case, stick a return in to cause the response to be returned.

if len(url) == 0:
    logging.info("""***len(url) is --zero--: %s***""" % len(url))
    self.redirect("/urlparseerror")
    return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM