I'm sometimes unsure how to use webapp2.redirect.
Is there ever a time when I should use
self.redirect("/blah")
instead of return self.redirect("/blah")
Here is my understanding/guess of the time-line: (sometimes i'm confused about if the response object does something or if webapp2 does it)
- I visit my multithreaded website www.mysite.com/name/robert, chrome sends a GET request (lets assume this request is a text file)
- webapp2 grabs this "text file" and turns it into a webapp2.Request. webapp2 also makes a new webapp2.Response.
- somehow the request url is given to the router for matching (either by webapp2 or by the response). An appropriate RequestHandler is instantiated. The RequestHandler's get() method is called with appropriate arguments.
- throughout this time there has only been one request and one response.
- the get() method calls response.out.write("hello world") adding "hello world" to the response body?
- the get() method calls self.redirect('/foo')
- Stuff happens
- the get() method calls self.out.write("bye world")
- the response is sent to the client containing hello world, what food added, bye world
example of the initial get function:
def get():
self.write('hello world')
self.redirect('/foo')
self.write('bye world')
What "stuff happens"? I suppose the router finds /foo/'s RequestHandler. What modifications are made to the Request and Response before foo's requestHandlers get() method is called. Is the request deleted and replaced by a new GET request? Is the response deleted and replaced by a new one? What context remains that was present in the initial request handler? does code execution return to the initial request handlers get method and if so is the context that may have existed restored?
Sorry If this is a bit of a mouthful, I've tried explaining what I want to know :)
Perhaps it would have been easier to ask for some use cases (do's and don'ts) of using redirect instead.