1

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?

Zeynel
  • 13,145
  • 31
  • 100
  • 145
  • url = self.request.get("url").strip() its equivalent to l and r strip. – topless Mar 06 '11 at 18:45
  • ok, thanks. But how does this stop redirect from executing? – Zeynel Mar 06 '11 at 18:47
  • it was just an observations try single quotes in request get like: url = self.request.get('url'), in order to execute the redirect you have to have a zero url, check if you are passing any string as url with length > 0 – topless Mar 06 '11 at 18:48
  • @Chris-Top: ozone's answer solved the problem. But why should I prefer single quotes over double quotes? I thought they were equivalent: http://stackoverflow.com/questions/56011/single-quotes-vs-double-quotes-in-python – Zeynel Mar 06 '11 at 19:32

1 Answers1

6

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
Chris Farmiloe
  • 13,935
  • 5
  • 48
  • 57