javascript - Python 在连接到服务器时显示网页

标签 javascript python sendfile

我使用 JavaScript 构建了一个服务器,当您连接到它时,它会显示一个网页。服务器在连接时发送 htm 文件,使用

app.get('/', function (req, res) {
    res.sendfile('index.htm');
});

Python中有类似的函数吗?

最佳答案

import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()

参见https://docs.python.org/2/library/simplehttpserver.html

关于javascript - Python 在连接到服务器时显示网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24744125/

相关文章:

python - Bash 或 Python 倒退?

python - 将 Python 脚本作为 upstart 服务运行显示不同的时间输出

javascript - 从第 3 方脚本修改 innerHTML

javascript - React 无法读取未定义的属性 'length' 但数组已定义

javascript - 我可以同时跟踪多个 Google Analytics 事件吗?

javascript - Node.js Expressjs 存储和显示 html 页面的最快方法

linux - 总是在 Linux 上将 sendfile 与 nginx 一起使用吗?

php - 单击并输入的不同行为

python - 修复 3D 图的锯齿状边缘,选择合适的掩码

ruby-on-rails - 如何通过 send_file 设置内容长度