in appengine how can i have namespace based url routing?
I'm trying to figure out how to change url routing based on namespace
Say I have myapp.x.com/apage and myapp.y.com/apage, I tried the code below but it doesn't work because I presume the main.py is being cached
ns = namespace_manager.google_apps_namespace()
if ns == 'x.com'
app = WSGIApplication([
(r'/apage', 'my.module.XHandler开发者_如何学Go'),
])
else:
app = WSGIApplication([
(r'/apage', 'my.module.YHandler'),
])
Is there any other way to do it besides of course turning each handler into a url router?
You need to write your own middleware that routes to different apps based on domain. See DomainMiddleware in this blog post for an example.
精彩评论