这里会显示出您选择的修订版和当前版本之间的差别。
— |
google:gae:redirect [2011/04/23 13:30] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Google GAE中使用重定向 ====== | ||
+ | ===== GAE 302 暂时重定向 ===== | ||
+ | request对象带有redirect函数可以实现重定向,redirect接受一个url网址作为重定向网址。 | ||
+ | 在默认参数的情况下,redirect函数实现的重定向为302暂时重定向。 | ||
+ | |||
+ | <code python> | ||
+ | class FormHandler(webapp.RequestHandler): | ||
+ | def post(self): | ||
+ | if processFormData(self.request): | ||
+ | self.redirect("/home") | ||
+ | else: | ||
+ | # Display the form, possibly with error messages. | ||
+ | </code> | ||
+ | ===== GAE 301 永久重定向 ===== | ||
+ | |||
+ | 其实Google App Engine 中实现301重定向非常简单,只要设置request对象redirect的可选参数 permanent=True 就可以实现301重定向了。 | ||
+ | |||
+ | <code python> | ||
+ | self.redirect("/home", permanent=True) | ||
+ | </code> | ||
+ | |||
+ | ===== 参考 ===== | ||
+ | * http://code.google.com/appengine/docs/python/tools/webapp/redirects.html |