1
votes

I want to create a temporary page where the browser lingers for a few seconds and is then redirected to another page. Working on python on Google App Engine. I thought the below should work(I am a total novice at this) but clearly it doesn't.

class TempPage(PageHandler):
        def get(self):
                self.response.write("You will be redirected to the Front page.")
                time.sleep(3)
                self.redirect('/')

PageHandler inherits from webapp2.RequestHandler.

Can someone please tell me what should be done.

Thanks

2
This is a duplicate of stackoverflow.com/questions/5203378/…OJFord

2 Answers

4
votes

I think that you want to use the meta refresh tag. There are some examples on that page, but you basically add a tag that looks like:

<meta http-equiv="refresh" content="TIME_TO_WAIT;URL='PAGE_TO_REDIRECT_TO'">

and put that in your <head> tag.

0
votes

The browser only receives the page when all your code has executed. In your code that is after self.redirect('/') is executed as that's the last line of code in the handler. You probably don't even see the text "You will be redirected to the Front page."

So all that happens here is that your webpage takes 3 seconds to load and then redirects immediately.

You might want to try redirecting the user via javascript in the page that you send them.

A similar question is asked and answered here: time delayed redirect?