Skip to content
A python

Quick and dirty server 2

Wednesday, 7 September 2022

At 178 words, this article should take about 1 minute to read.

I wrote last year about spinning up a quick and dirty server using Python.

Since then, I have moved to using Python 3 (woop woop!) and, the first time I ran my funky little srv 1337 function I got an error! 😱

"No module named SimpleHTTPServer"

According to the Python 2.7 documentation

The SimpleHTTPServer module has been merged into http.server in Python 3.

So, the simple-enough solution is to replace SimpleHTTPServer with http.server.

  1. Navigate to the folder you want to serve
  2. python -m http.server
  3. Open http://localhost:8000

What if PORT 8000 is in use?

Pass a different port number like this: python -m http.server %%PORT_NUMBER%%

If you want it to be even simpler - stick this somewhere in your bash config!

srv() {
  python -m http.server $1
}

As before, it doesn't come with any of the fancy stuff that other "local server" plugins might come with like hot reloading or compiling Scss but, if all you want is a small static site launching, why reach for another dependency?

Cover image courtesy of David Clode.


Fin

Comments

In almost all cases, the comments section is a vile cesspool of Reply Guys, racists, and bots.

I don't want to have to deal with that kind of hell so I don't have a comments section.

If you want to continue the conversation, you can always hit me up on Mastodon (which is not a vile cesspool of Reply Guys, racists, and bots).

Thomas Rigby

Thomas Rigby

When I'm not building things for the internet, I take photos of stuff.

Real. Simple. Syndication.

Get my latest content in your favorite RSS reader. I use InoReader but you don't have to.

What even is an RSS feed?!

Subscribe

Last played

Inferno

Ad Infinitum || Chapter 2: Legacy

Listen
Loading Invisible Visible RSS Navigation Close Arrow Info Online Online