Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect user in Python + Google App Engine

I'm trying to do a simple redirection after logging the user. I thought I could use the print "Location:..." method but that doesn't seem to do the trick.

class MainPage(webapp.RequestHandler):
    def get(self):

        ip = self.request.remote_addr
        log = Log()
        log.ip_address = ip
        log.put()
        print "Location:http://www.appurl.com"
like image 831
Ian McIntyre Silber Avatar asked Nov 20 '10 04:11

Ian McIntyre Silber


1 Answers

RequestHandler has a redirect() method that you can use. It takes two parameters, the first one being the url to redirect to, and the second one a boolean value. If you pass true, it sends a 301 code to indicate a permanent redirect, if you don't pass it an explicit value, it defaults to false, and sends the client a 302 code to indicate a temporary redirect.

Something like this:

class MainPage(webapp.RequestHandler):
    def get(self):

        ip = self.request.remote_addr
        log = Log()
        log.ip_address = ip
        log.put()
        self.redirect("http://www.appurl.com") # replaced this -> print "Location:http://www.appurl.com"
like image 161
Alex Avatar answered Sep 17 '22 15:09

Alex