Back to Blog

Running a Local Web Server Using Python—Brief Notes

November 20, 2025

While building this blog, I wanted to check how it looked without typing "file:///full/path/to/htmlfiles" into the browser. A quick search yielded this post, which I skimmed, and found out it was easy to do with Python. From there, I headed to the docs for Python's http.server module.

Basic command line usage—

% python3 -m http.server

Originally ran this with --bind 127.0.0.1, but realized that if I skip that option, then I can locally test my website on other devices connected to the LAN. That's great for being able to preview the site on a phone or tablet, which used to be more of a hassle when I was first learning html, and didn't understand IP addresses, ports, etc. Back then, the main way I used to check a site on my phone was to push to GitHub, trigger a new Netlify build / deployment, and temporarily let half-finished work float around on the internet so I could see how it looked.

To terminate the server, just hit Ctrl-C, like interrupting most other processes. If you keep an eye on the terminal window while the server is running, prior to terminating it, you'll see that it stays active... so Ctrl-C makes sense.

Serves to port 8000 by default

For desktop browser, loopback address on that port unless you specified a different port—127.0.0.1:8000

To view on your phone, do the following—

To find your desktop's local IP address, use

% ifconfig | grep -w inet

which filters out the inet6 / IPv6 addresses, so there are only a few to choose from. Use whichever entry [1] starts with 192. (most common), 172., or 10.; and [2] includes a broadcast address, which will end in .255

Side note—indent this, please—I used to just grep for inet and then skim through the additional search results to find the IPv4 addresses, but picked up the -w [switch] for matching exact patterns—and explicitly omitting borderline matches that include anything extra—during Jaron Bradley's training at OBTS v8.0. To be fair, I imagine most people reading this already know about that [switch], but it was new to me, and has made grep a lot more efficient since.

For iPhone on iOS 26.x, Settings > Apps > Safari > Privacy & Security heading > Not Secure Connection Warning toggle switch -> off

You should now be able to see your site locally, before pushing to GitHub > triggering a Netlify / other deployment.