defining sub-domain based on a function in routes.py of Web2Py

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 17:46:25

Ok, so i think misinterpreted this a little. You need user9.mysite.org to be served from the web2py app. One way, if you have your site hosted at mysite.org, is to pass all requests (regardless of subdomain) to the web2py application (you'll need an A record like *.mysite.org with your DNS provider: http://kb.mediatemple.net/questions/791/DNS+Explained#/A_Record )

Then, you can use routes

Something like:

routes_in = (
  ('http://(?P<user>.*).mysite.org/(?P<any>.*)',
  '/app/pages/blog/\g<any>?name=\g<user>'),
) 

The <any> will save any args you may need. This should map a request from user9.mysite.org to mysite.org/app/pages/blog/<args>?name=user9

You might have to play with it a little to get it working. The key is to make sure that a request to any subdomain of mysite.org be given directly to the app. Meaning if you go to www.mysite.org, mysite.org, somerandomfakesubdomain.mysite.org, you'll always get to the same place as mysite.org. You'll probably want to put some logic in your blog function to ensure that the subdomain string (e.g. user9) represents a valid user.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!