这里会显示出您选择的修订版和当前版本之间的差别。
google:gae:request-url [2010/06/02 01:18] |
google:gae:request-url [2010/06/02 01:18] (当前版本) |
||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 得到request的URL地址 ====== | ||
+ | 得到的request的URL地址,我们就可以根据request的URL地址用GAE动态的生成网页内容。 | ||
+ | |||
+ | ===== 程序代码 ===== | ||
+ | |||
+ | <code python> | ||
+ | from google.appengine.ext import webapp | ||
+ | from google.appengine.ext.webapp.util import run_wsgi_app | ||
+ | |||
+ | class MainPage(webapp.RequestHandler): | ||
+ | def get(self): | ||
+ | header = str(self.request) | ||
+ | self.response.headers['Content-Type'] = 'text/plain' | ||
+ | self.response.out.write('Hello, webapp World!\n') | ||
+ | self.response.out.write(header) | ||
+ | |||
+ | application = webapp.WSGIApplication( | ||
+ | [('/.*', MainPage)], | ||
+ | debug=True) | ||
+ | |||
+ | def main(): | ||
+ | run_wsgi_app(application) | ||
+ | |||
+ | if __name__ == "__main__": | ||
+ | main() | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ===== 访问结果 ===== | ||
+ | |||
+ | |||
+ | 访问下面的地址时 | ||
+ | |||
+ | %%http://localhost:8080/dfasf%% | ||
+ | |||
+ | 可以得到 | ||
+ | |||
+ | <code> | ||
+ | Hello, webapp World! | ||
+ | GET /dfasf | ||
+ | Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 | ||
+ | Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 | ||
+ | Accept-Language: en-us,en;q=0.5 | ||
+ | Connection: keep-alive | ||
+ | Content-Length: | ||
+ | Content-Type: application/x-www-form-urlencoded | ||
+ | Host: localhost:8080 | ||
+ | Keep-Alive: 300 | ||
+ | User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 | ||
+ | </code> |