利用python建立web服务器

from functools import partial  # 导入模块
from http.server import HTTPServer, SimpleHTTPRequestHandler

if __name__ == '__main__':
    ip = ''
    port = 8888
    # 指定directroy 的路径 ,返回给Handler这个对象,在去调用这个对象
    Handler = partial(SimpleHTTPRequestHandler, directory='/home/pi/Downloads')
    server = HTTPServer((ip, port), Handler)
    server.serve_forever()

指定目录

from functools import partial  # 导入模块
from http.server import HTTPServer, SimpleHTTPRequestHandler

if __name__ == '__main__':
    ip = ''
    port = 8888
    # 指定directroy 的路径 ,返回给Handler这个对象,在去调用这个对象
    Handler = partial(SimpleHTTPRequestHandler, directory='/home/pi/Downloads')
    server = HTTPServer((ip, port), Handler)
    server.serve_forever()