Home

Tags

Как быстро расшарить любую папку по http без установки тяжелого веб сервера

2010-02-07 python bottle

Напишем веб-сервер с использованием bottle (20 строк кода)

Для использования нужен пакет bottle:

easy_install bottle

Исходник:
# coding: utf-8

from bottle import run, route, send_file
import os

# список текущих файлов
@route('/')
def main():
    msg = ''
    for file in os.listdir('.'):
        if os.path.isfile(file): msg += '<a href="%s">%s</a><br/>\n' % (file,file)
    return '<html><body>%s</body></html>' % (msg,)

# отправка файла
@route(':filename')
def sendfile(filename):
    send_file(filename, './')

# запуск сервера
run(host='', port=8080)

запускаем скрипт - файлы доступны: http://localhost:8080/


Продолжение: Простая авторизация в web