问题

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

解法

blog.py中:

import web
urls = (
  "", "reblog",
  "/(.*)", "blog"
)

class reblog:
    def GET(self): raise web.seeother('/')

class blog:
    def GET(self, path):
        return "blog " + path

app_blog = web.application(urls, locals())

当前的主应用code.py:

import web
import blog
urls = (
  "/blog", blog.app_blog,
  "/(.*)", "index"
)

class index:
    def GET(self, path):
        return "hello " + path

app = web.application(urls, locals())

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

由于博客空间在国外,所以有时会造成不稳定(你懂滴),如果您觉得我的博文对您有帮助, 建议大家多使用RSS访问阅读,本站所有文章均已全文输出。
鲜果阅读器订阅图标

Fork me on GitHub