/ tuesdaytooling

Tooling Tuesday - Python3 Web Server

alt
Something simple, yet so handy! A Python 3 web server ready to serve content!

So what is it?

A simple HTTP server that can serve web pages and share files.

So it's like Apache / nginx / (insert other web server here) ?

Well no, it isn't as complex, but therein lies the beauty, we can serve files/pages using one line in the terminal rather than configuring services.

How can I use it?

Well the best thing is, if you have Python 3 installed on your machine, then you already have it!

Let's say we have some files that we wish to share with others on the network.

So an example, we have some hilarious cat pictures that Accounts really need to see! So we navigate to the directory (folder) containing the cat pics, open a terminal and type.

python3 -m http.server

alt
Now open a browser to 127.0.0.1:8000 and behold you can see your cat pics!

But how do the Accounts team see them? Jim loves cats and he needs to know how to get to them. Well Jim can see the pics if we tell him the IP address of our machine. This can be found in the Network settings section of your Control Panel.
Linux peeps can open a Terminal and type...

hostname -I

or use the new ip tool.

ip addr

Now send Jim a message with your IP address followed by :8000

For example mine was 192.168.0.8:8000

alt

Can I serve web pages using this?

Yes! But there is a caveat, this is not a production web server! Let me be clear, do not use this to serve your website, use a proper web server. This tool is handy for a quick web server, say for a trade show, school event, cat picture sharing over corporate network

If there is a file called index.html then the web server will serve that page by default.

alt
So we knocked up a quick Bootstrap page with cat pics, 'cos Jim in Accounts LOVES cat pics!

Have fun, but remember. Use this for good, don't spam across corporate or school networks, that would be bad!