Search code examples
pythonhtmlserverbottle

Bottle server route to multiple html pages


I have set up a bottle server and I want to launch both index.html and second.html pages which are located in my main website folder. The code I've previously used to display index.html is:

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

At the moment, it won't work and it will throw a server error saying that the file does not exist. How can I launch not only my index, but my other pages as well?


Solution

  • root needs to be the path to the folder containing your files, not the file itself:

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

    So requesting example.com/index.html will serve the file at /path/to/files/index.html.