I have a simple python script that I want to serve as a website:
import SimpleHTTPServer
import SocketServer
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
I'm in that folder and run
$ python3 -m http.server
then I visit http://hassbian.local:8000/song.py
The terminal says this and I get the file as a txt file, the script won't execute.
Serving HTTP on 0.0.0.0 port 8000 ...
192.168.1.115 - - [04/Jun/2017 14:19:59] "GET / HTTP/1.1" 200 -
192.168.1.115 - - [04/Jun/2017 14:20:04] "GET /song.py HTTP/1.1" 200 -
Running on a rasberry pi
python3 -m http.serverwill simply serve files from the directory on which you ran it.