用户工具

站点工具


google:gae:redirect

Google GAE中使用重定向

GAE 302 暂时重定向

request对象带有redirect函数可以实现重定向,redirect接受一个url网址作为重定向网址。

在默认参数的情况下,redirect函数实现的重定向为302暂时重定向。

class FormHandler(webapp.RequestHandler):
    def post(self):
        if processFormData(self.request):
            self.redirect("/home")
        else:
            # Display the form, possibly with error messages.

GAE 301 永久重定向

其实Google App Engine 中实现301重定向非常简单,只要设置request对象redirect的可选参数 permanent=True 就可以实现301重定向了。

self.redirect("/home", permanent=True)

参考

google/gae/redirect.txt · 最后更改: 2011/04/23 13:30 (外部编辑)