Search code examples
pythonweb.pyurl-mapping

Mapping user site to their own url in a web.py application


I'm coding a web app with web.py allowing users to add some html pages.

Currently, the pages are mapping like that:

webapp.com/user1/page1
webapp.com/user1/page2
webapp.com/user2/page1
webapp.com/user3/page1

I know web.py can manage subdomains to have:

user1.webapp.com/page1
user2.webapp.com/page2
...

If the user would like his pages to appear under a custom domain URL that he control, such as www.user-own-url.com, I would like to give him the option.

Is it possible to do it with web.py? Or is there another python solutions to do that?


Solution

  • It is possible, but you'll have to subclass application class and code your own url mapping so it will depend on web.ctx.host value instead of just matching against web.ctx.path

    Or you may add loadhook for every request, where you check web.ctx.host and load needed user into web.ctx to use later in the controller method.