在Google应用引擎中使用子域名 [英] Working with subdomain in google app engine
问题描述
如何在Google应用引擎(python)中使用子域名。
我想获得第一个域名部分并采取一些操作(处理程序)。
> 示例:
product.example.com - >将其发送到产品处理程序
user.example.com - >将其发送给用户处理程序
实际上,使用虚拟路径我有这样的代码:
application = webapp.WSGIApplication(
[('/',IndexHandler),
('/product/(.*)',ProductHandler),
('/user/(.*)',UserHandler)
]
WSGIApplication不能基于域进行路由,而是需要为每个应用程序创建一个单独的应用程序子域,如下所示:
applications = {
'product.example.com':webapp.WSGIApplication([
('/',IndexHandler),
('/(.*)',P $ b $''user.example.com':webapp.WSGIApplication([
('/',IndexHandler),
('/(.*)',UserHandler)] ),
}
def main():
run_wsgi_app(applications [os.environ ['HTTP_HOST']])
if __name__ == '__main__':
main()
或者,您可以编写自己的WSGIApplication子类知道如何处理多个主机。
How can I work with sub domain in google app engine (python).
I wanna get first domain part and take some action (handler).
Example:
product.example.com -> send it to products handler
user.example.com -> send it to users handler
Actually, using virtual path I have this code:
application = webapp.WSGIApplication(
[('/', IndexHandler),
('/product/(.*)', ProductHandler),
('/user/(.*)', UserHandler)
]
WSGIApplication isn't capable of routing based on domain. Instead, you need to create a separate application for each subdomain, like this:
applications = {
'product.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', ProductHandler)]),
'user.example.com': webapp.WSGIApplication([
('/', IndexHandler),
('/(.*)', UserHandler)]),
}
def main():
run_wsgi_app(applications[os.environ['HTTP_HOST']])
if __name__ == '__main__':
main()
Alternately, you could write your own WSGIApplication subclass that knows how to handle multiple hosts.
这篇关于在Google应用引擎中使用子域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!