Google App Engine: Redirecting to RequestHandler

I was just starting out with the Google App Engine using python, and I followed the tutorial and wrote my little app to get familiar with the webapp map. Now I just noticed that in the tutorial below self.redirect('/'). So I wondered: is there a way to redirect to a handler instead of a hard-coded path? Thought it might be better so that you can change your URLs without breaking your application.

+3
source share
3 answers

One alternative would be to have a symbolic name map for URLs, so you could redirect to the associated URL - you could update your URLs with impunity.

Or, if you just want to execute code from another handler, I don’t know why you couldn’t just call a method call - the worst case scenario, you could extract a common method from two handlers and call it.

+3
source

This is not a limitation for App Engine, just like the webapp platform. webapp is designed to facilitate the work with the database.

If you want fancier redirection behavior , try Django.

+1
source

, , webapp2 , , , webapp2 Uri

app = webapp2.WSGIApplication(
              routes=[webapp2.Route('/', handler='RootController', name='root')])

RequestHandler

self.redirect_to('root')

If your path contains placeholders, you can specify values ​​for placeholders, and webapp2.Router will build the correct uri for you. Browse webapp2 Uri routing again for more details.

0
source

Source: https://habr.com/ru/post/1755033/


All Articles