• 使用子应用
    • 问题
    • 解法

    使用子应用

    问题

    如何在当前应用中包含定义在其他文件中的某个应用?

    解法

    blog.py中:

    1. import web
    2. urls = (
    3. "", "reblog",
    4. "/(.*)", "blog"
    5. )
    6. class reblog:
    7. def GET(self): raise web.seeother('/')
    8. class blog:
    9. def GET(self, path):
    10. return "blog " + path
    11. app_blog = web.application(urls, locals())

    当前的主应用code.py:

    1. import web
    2. import blog
    3. urls = (
    4. "/blog", blog.app_blog,
    5. "/(.*)", "index"
    6. )
    7. class index:
    8. def GET(self, path):
    9. return "hello " + path
    10. app = web.application(urls, locals())
    11. if __name__ == "__main__":
    12. app.run()