Skip to content

Instantly share code, notes, and snippets.

@mtayseer
Created March 15, 2014 06:59
Show Gist options
  • Save mtayseer/9562792 to your computer and use it in GitHub Desktop.
Save mtayseer/9562792 to your computer and use it in GitHub Desktop.
Static files server using Bottle web framework
'''Static files server using Bottle web framework'''
# You can use the command `python -m SimpleHTTPServer`, but when you want to
# do more, use this snippet
from bottle import route, run, static_file
@route('/')
@route('/<path:path>')
def serve(path='index.html'):
response = static_file(path, root=OUTPUT_ROOT)
# if the user wants a directory, I search for index pages
if path.endswith('/') and response.status_code == 404:
for file in ['index.html', 'index.htm']:
response = static_file(path + file, root=OUTPUT_ROOT)
if response.status_code != 404:
return response
return response
run(host='localhost', port=8080, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment