开发必备
开源协议

- 来源:如何选择开源许可证?
Python 起一个 HTTP 服务
python3 -m http.server这样中文会有乱码,可以这么解决:
#!/usr/bin/env python3
import http.server
import socketserver
class ChineseHTTPRequestHandler(http.server.SimpleHTTPRequestHandler):
# 动态修改扩展名映射,为所有文本类型文件增加 utf-8
extensions_map = http.server.SimpleHTTPRequestHandler.extensions_map.copy()
extensions_map.update({
'.html': 'text/html; charset=utf-8',
'.txt': 'text/plain; charset=utf-8',
'.md': 'text/markdown; charset=utf-8',
'.js': 'application/javascript; charset=utf-8',
'.css': 'text/css; charset=utf-8',
'': 'text/plain; charset=utf-8', # 无后缀文件
})
PORT = 8000
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer(("", PORT), ChineseHTTPRequestHandler) as httpd:
print(f"Serving at http://localhost:{PORT} with full Chinese support...")
httpd.serve_forever()保存成 utf8-server.py ,后执行:
python3 utf8-server.py