0

web.py 带有一个内置的 http 服务器,足以满足我的测试需求。我在 server.py 中定义了以下 2 个端点。

/login
/info

我的文件夹结构是这样的。

app
|__api
|__|__login.py
|__|__info.py
|__|__server.py
|__www
|__|__index.html
|__|__app.js

在终端中,我只运行以下命令。

$ python app/api/server.py

上面的设置有效,但我要添加的是一个根 ( / ) 去www/并提供 index.html。我可以用 web.py 内置服务器做到这一点吗?

4

1 回答 1

2

自己写的:)

urls = (
    '/(.*)', 'General'
)

class General:
    app_dir = 'www'

    def GET(self, path):
        root = os.path.abspath(os.path.join('.', os.pardir))
        dest = '%s/%s/index.html' % (root, self.app_dir)
        if path:
            dest = '%s/%s/%s' % (root, self.app_dir, path)
        with open(dest, 'r') as f:
            return f.read()
        return ''
于 2013-09-13T13:22:59.217 回答