« Amazon hit by 'shopping cart' patents lawsuit | Main | On the subject of Hamas »
March 18, 2004
One line Python Web server
if you have python installed, go to your terminal and cd to the directory you want to serve HTML files from, then type:
python -c "import SimpleHTTPServer;SimpleHTTPServer.test()"
and your HTML files will be served on port 8000. :) From Kevin Altis' blog.
Update: I just noticed that TypePad truncates the last few characters of the line, and I don't have the heart to fold it over -- it's supposed to be one line, darn it! But you can see it in its full glory at the link to Kevin's blog today. It's handy -- we actually had use for it today to run a quick test.
Update 2: A commenter pointed out an even shorter version:
python -m SimpleHTTPServer
Unfortunately that doesn't work in Python 3.0. Niklas points out that in 3.0, you can use
python3.0 -c ‘import http.server as h;
h.test(HandlerClass=h.SimpleHTTPRequestHandler)’
but I haven't tried it because I don't have 3.0 installed yet.
March 18, 2004 in Web/Tech | Permalink
Comments
This is great! Also see my story about how this is better than Samba, Apache and Firefox together ;-).
Posted by: Anton at Nov 27, 2005 11:05:01 AM
Thanks for writing, I enjoyed your story!
Posted by: Gary Robinson at Nov 27, 2005 11:23:22 AM
That made my day. So simple!
Posted by: Arlo Emerson at Jun 10, 2008 3:45:28 PM
If it's too long, try
python -c 'from SimpleHTTPServer import test;test()'
:)
Posted by: ZeD at Nov 5, 2008 10:51:37 PM
Even more compact:
python -m SimpleHTTPServer
Beautiful!
(Via masklinn's comment of Ed Taekema's blog post.)
Posted by: Niklas at Nov 6, 2008 8:39:17 AM