How To Setup a Simple Web Server in Python

Simple is better than complex.

Yang Zhou
TechToFreedom

--

How To Setup a Simple Web Server in Python
Photo by Hal Gatewood on Unsplash

Yesterday, I would like to review some files while I was taking a bath. 🛀 Unfortunately, these files were in my Mac Mini instead of my mobile phone. To make matters worse, I didn’t have an iPhone. (Yes, I am using an M1 Mac Mini but an Android phone.)

The AirDrop, as we all know, is a super convenient application to transfer data between iPhone and Mac. But it doesn’t support Android phones and it’s maybe too late to buy a new iPhone before I started taking a bath yesterday.

Of course, there may be many third-party tools that can help. After googling them, I found there are too many choices in this case. Because of my decidophobia, it’s stressing me out.

So, as a Python expert (self-defined), I was wondering if Python can help me.

After thinking for a while, I got it! All I needed was just one line of Python code:

python3 -m http.server

The above code can start a very simple Web server serving files relative to the current directory, and the default port of it is 8000. Then, I just needed to open the 192.168.x.xx:8000 with my Android phone to check out the files directly and seamlessly. (By the way, 192.168.x.xx stands for my Mac Mini’s IP address.)

--

--