| — |
google:gae:diff-host-response [2012/01/12 05:51] (当前版本) |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| + | ====== Google App Engine Host来处理请求 ====== | ||
| + | |||
| + | ===== GAE绑定域名重定向 ===== | ||
| + | |||
| + | GAE绑定域名后,原来的appspot不会自定重定向到域名,这里我们可以判断 self.request.host 来实现自动重定向。 | ||
| + | |||
| + | <code python> | ||
| + | class home_handler(webapp.RequestHandler): | ||
| + | def get(self): | ||
| + | if not (self.request.host == "www.pythonclub.org" or self.request.host == "localhost:8080"): | ||
| + | taonot_url = "http://www.pythonclub.org" + self.request.path | ||
| + | self.redirect(taonot_url, permanent=True) | ||
| + | return | ||
| + | </code> | ||
| + | |||
| + | ===== GAE根据不同Host完成不同处理 ===== | ||
| + | |||
| + | 对同一个GAE应用,我们可以绑定多个域名,这样我们就可以根据不同域名来进行不同的处理。 | ||
| + | |||
| + | <code python> | ||
| + | class home_handler(webapp.RequestHandler): | ||
| + | def get(self): | ||
| + | if self.request.host == "www1.pythonclub.org": | ||
| + | self.get_www() | ||
| + | elif self.request.host == "www2.pythonclub.org": | ||
| + | self.get_www2() | ||
| + | else: | ||
| + | self.get_www() | ||
| + | |||
| + | def get_www(self): | ||
| + | echo "host www" | ||
| + | |||
| + | def get_www1(self): | ||
| + | echo "host www1" | ||
| + | |||
| + | def get_www2(self): | ||
| + | echo "host www2" | ||
| + | </code> | ||
| + | |||
| + | ==== 参考 ==== | ||
| + | * http://docs.webob.org/en/latest/index.html | ||