我有一个静态文件的路由定义为
@bottle.route('/status/<filename>')
def server_static(filename):
root = os.path.join(os.path.dirname(__file__), 'status', 'public_html')
return bottle.static_file(filename, root=root)
当我调用 http://localhost/status/index.html(或任何其他文件)时它工作正常。
有没有办法在调用http://localhost/status时默认提供index.html?这相当于DirectoryIndex在 Apache 中或在 nginx 中为 index。
请您参考如下方法:
添加/status规则并将filename的默认值设置为index.html:
@bottle.route('/status')
@bottle.route('/status/<filename>')
def server_static(filename='index.html'):
root = os.path.join(os.path.dirname(__file__), 'status', 'public_html')
return bottle.static_file(filename, root=root)
