GAE Google AppEngine - 如何在Python27线程安全中处理子域内应用内路由? [英] GAE Google AppEngine - How to handle subdomain in-app routing in Python27 threadsafe?

查看:104
本文介绍了GAE Google AppEngine - 如何在Python27线程安全中处理子域内应用内路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在GAE Python25中使用下面的代码来处理应用程序中的请求的应用程序内路由:www.example.com和blog.example.com(注意子域的区别),使用以下代码: p>

 #app.yaml 
- url:/
脚本:main.py

#main.py
applications = {
'www.example.com':webapp.WSGIApplication([('/',MainHandler)],
debug = False),
'blog.example.com':webapp.WSGIApplication([('/',BlogHandler)],
debug = False)
}

def main():
host = os.environ ['HTTP_HOST']
如果应用程序中的主机为:
run_wsgi_app(applications [host])
else:
run_wsgi_app(applications ['www。 example.com'])

if __name__ =='__main__':
main()

但在Python27中,格式有些不同。它是以下内容:

 #app.yaml 
处理程序:
- url:/
脚本:main.app#(而不是main.py)


#main.py
app = webapp2.WSGIApplication([(r'/',MainPage)], debug = True)

如何在Python27(threadsafe)中实现相同的功能,并路由不同的子域给应用程序中的不同处理程序?



谢谢!

谢谢!
<只需使用webapp2域路由 http://webapp-improved.appspot.com/guide/routing.html#domain-and-subdomain-routing


I used to do this in GAE Python25 to handle in-app routing of requests to www.example.com and blog.example.com (Notice the difference in subdomains) within the same app, using the code below:

#app.yaml
- url: /
  script: main.py

#main.py
applications = {
  'www.example.com': webapp.WSGIApplication([('/', MainHandler)],
                                      debug=False),
  'blog.example.com': webapp.WSGIApplication([('/', BlogHandler)],
                                      debug=False)
}

def main():
    host = os.environ['HTTP_HOST']
    if host in applications:
        run_wsgi_app(applications[host])
    else:
        run_wsgi_app(applications['www.example.com'])

if __name__ == '__main__':
  main()

But in Python27, the format is something different. It's the following:

#app.yaml
handlers:
- url: /
  script: main.app  # (instead of main.py)


#main.py
app = webapp2.WSGIApplication([(r'/', MainPage)],debug=True)

How do I achieve the same functionality in Python27 (threadsafe), and route different subdomains to different handlers within the app?

Thanks!

Thanks!

解决方案

Just use webapp2 domain routing http://webapp-improved.appspot.com/guide/routing.html#domain-and-subdomain-routing

这篇关于GAE Google AppEngine - 如何在Python27线程安全中处理子域内应用内路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆