mr_ivan777
mr_ivan777

Reputation: 401

Google appengine. How to redirect inside handler constructor

I have simple handler class:

class my_handler(webapp2.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(my_handler, self).__init__(*args, **kwargs)
        self.redirect("/")

but redirrect doesn't work. What is the bast way to do it?

Upvotes: 1

Views: 171

Answers (3)

Jimmy Kane
Jimmy Kane

Reputation: 16825

This maybe

self.redirect('/')

and if you want immediate without execution of script (without adding return)

self.redirect('/', abort=True)

Read more at the webapp2 docs about redirect

Upvotes: 1

Dave W. Smith
Dave W. Smith

Reputation: 24956

The way to get a redirect to happen is to call redirect from get (or post, if that's what you need).

Upvotes: 0

Greg
Greg

Reputation: 10360

You should override dispatch instead, and redirect instead of calling super().

Upvotes: 1

Related Questions