One-line web server in Python
## 2022/10/14
These days the incantation is
See the [http.server documentation](https://docs.python.org/3/library/http.server.html#module-http.server).
----
## Original Post
From Ed Taekema's weblog, a reminder[1] about how to create a web server in one line of Python:
This starts a server listening on port 8000, serving files from its launch directory. If you just hit the server (
[1] Reminder? It's been a long time since I read "Internet Programming with Python" :-)
$ python -m http.server
python -c 'import SimpleHTTPServer;SimpleHTTPServer.test()'
http://localhost:8000/
) it will by default serve index.html
; if index.html
doesn't exist, it will give you a directory listing. Also, the server will provide only those files residing in or below the current working directory; e.g. http://localhost:8000/../
resolves to the default document.
Wish I'd seen Ed's note this morning...
This is handy when you want to experiment with things like interactions between Flex applications and JavaScript, or other situations in which you can't get by with simple file:///
URLs. This would be handy as a jqUnit test, as well.
[1] Reminder? It's been a long time since I read "Internet Programming with Python" :-)