Serve local HTML and CSS files with http.server
Aug 22nd, 2024
![](/assets/img/posts//serve-local-html-and-css-files-with-http-server/serve-local-html-and-css-files-with-http-server-cover.png)
Batteries included is a blog series about the Python Standard Library. Each day, I share insights, ideas and examples for different parts of the library. Blaugust is an annual blogging festival in August where the goal is to write a blog post every day of the month.
In addition to importing functionality from standard library modules to your
Python scripts, some modules can be run with
python -m [module]
(docs), providing nice command line tooling.
Today we look at one of those options,
http.server
.
If you have folder with HTML and CSS files like this:
$ tree
.
├── about.html
├── css
│ ├── feature.css
│ └── main.css
├── feature.html
└── index.html
2 directories, 5 files
You can serve them locally with
$ python -m http.server
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
and browse through your website.