瓶服务器路由到多个HTML页面

时间:2019-01-25 20:58:56

标签: python html server bottle

我已经设置了一个瓶子服务器,我想启动位于我的主网站文件夹中的index.html和second.html页面。我以前用来显示index.html的代码是:

@route('/')
def server_static(filename="index.html"):
    return static_file(filename, root='./index.html')

目前,它不起作用,并且将引发服务器错误,指出该文件不存在。如何不仅可以启动索引,还可以启动其他页面?

1 个答案:

答案 0 :(得分:1)

root必须是包含文件的文件夹的路径,而不是文件本身:

@route('/<filename>')
def server_static(filename):
    return static_file(filename, root='/path/to/files')

因此,请求example.com/index.html将在/path/to/files/index.html处提供文件。

相关问题