# Multiple web apps

The approach I am proposing here is slightly different from the one  
proposed by Adam Atlas in https://bugs.launchpad.net/webpy/+bug/119365.

     import web

     app = web.app()
     urls = ("/.*", "hello")

     class hello:
         def GET(self):
             print "hello, world!"

     if __name__ == "__main__":
         app.run(urls, globals())

Each app maintains its own state including loadhooks, unloadhooks etc.

It is possible to implement this without breaking the backward  
compatibility.
This approach can be extended to support multiple subdirs and  
multiple subdomains by adding app.setup method.

     # blog.py
     import web

     app = web.app()
     urls = ("/.*", "blog")
     app.setup(urls, globals())

     class blog:
        "blah blah blah"
         pass

     # wiki.py
     import web

     app = web.app()
     urls = ("/.*", "wiki")
     app.setup(urls, globals())

     class wiki:
        "blah blah blah"
         pass

     # subdir.py
     import web
     import wiki
     import blog

     app = web.subdir_app("/wiki", wiki.app, "/blog", blog.app)

     if __name__ == "__main__":
         app.run()

     # subdomain.py
     import web
     import wiki
     import blog
     import web20

     app = web.subdomain_app(
         "wiki\.example\.com", wiki.app,
         "blog\.example\.com", blog.app,
         ".*\.example\.com", web20.app)

     if __name__ == "__main__":
         app.run()

Using these multiple applications can be combined into one single web  
application very easily.

# Multiple databases

     import web
     app = web.app()
     db = web.database(app, dbn='mysql', db='wiki', user='root',  
pw='', pooled=True)

     class wiki:
         def GET(self, path):
             d = db.query('SELECT * FROM wiki WHERE path=$path",  
vars=locals())
             ....

Since all the state is stored in the db object, it is possible to  
create multiple DB connections. app is passed to the database because  
it needs to register a look hook with the app.

Again here also it is possible to maintain backward compatibility.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to