您的位置:首页 > 其它

Web.py Cookbook 简体中文版 - 使用子应用

2012-11-23 11:07 281 查看

问题

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

解法

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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: