Okay, so today I decided to dive into something I’ve been meaning to try for ages – setting up a simple web server using Python. Nothing fancy, just a little something to serve up a basic HTML file. It’s like, a rite of passage for anyone messing around with web stuff, you know?
Getting Started
First things first, I made sure I had Python installed. Pretty sure I did, but I double-checked anyway. Just typed `python –version` into my command prompt, and yep, there it was. Good to go.
Then, I whipped up a super simple HTML file. Just the bare bones:
<!DOCTYPE html>
<html>
<head>
<title>My Test Page</title>
</head>
<body>
<h1>It Works!</h1>
</body>
</html>
Saved that as `*` in a new folder I created called `web_server_test`. Gotta keep things organized, even for little projects.
Firing up the server
Next, I opened up my command prompt and navigated to that `web_server_test` folder using the `cd` command. I always feel like a bit of a hacker when I’m using the command prompt.
Now for the magic. I typed in this little command:
`python -m *`
And boom! It spat out something like:
“Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) …”
Checking it out
So, I opened up my web browser and typed `http://localhost:8000` into the address bar. And there it was! My super basic “It Works!” page, served up by my very own little Python web server. It’s like, a tiny little website, living on my computer!
That `8000` is the default way to server a web, if I want use others,I can also use command like:
`python -m * 8080`
Felling
It’s such a small thing, but it felt pretty cool to get that working. It’s like, you build something, and it actually does something. I’ve always digged doing this. And this is just the beginning. I’m already thinking about what else I can do with this. Maybe serve up some images, or even try a little dynamic content. The possibilities, man!