Using Sub-applications on web.py

I have started learning the web.py framework for python. It’s simply a great framework. Here’s a code snippet I wrote a few minutes ago to try the sub-application feature of web.py.

There is mainly two applications here à “app” and “viewapp”. The “app” application maps “/view” url to the “viewapp” application while the later handles any request passed to it [ "/(.*)" ] and prints out the requested url.

This can be helpful for creating well structured URLs like http://localhost/view/1034 which will retrieve the article ID 1034 from the database.

Here’s the code:

import web
class view:
def GET(self,path):
return path
urls2 = ("/(.*)","view")
viewapp = web.application(urls2,globals())
urls = ("/view",viewapp)
app = web.application(urls,globals())
if __name__ == "__main__":
app.run()

Tags: , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">