0

I built a server using JavaScript that displayed a webpage when you connected to it. The server sent the htm file upon connection using

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

Is there a similar function in Python?

putty174
  • 305
  • 5
  • 19

1 Answers1

2
import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

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

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

see https://docs.python.org/2/library/simplehttpserver.html

beiller
  • 3,105
  • 1
  • 11
  • 19