Local Testing with Python
This guide explains how to run a simple local web server using Python so you can test static web projects safely on your own computer before uploading changes to a live site.
It was written with this project’s structure in mind, but the same general workflow is useful for many small HTML, CSS, and JavaScript projects.
Why Use a Local Server?
- Test changes safely on your own computer
- Avoid breaking the live site
- Preview HTML, CSS, and JavaScript in a browser
- Develop faster without repeatedly uploading files
A local server creates a simple workflow: edit a file, save it, refresh the browser, and immediately see the result.
Quick Start for This Project
For this project specifically, start the server from the folder
above the textAnalysis directory.
cd path/to/the/folder-above-textAnalysis
python -m http.server 8000
If that command does not work, try:
python3 -m http.server 8000
Then open this exact address in your browser:
http://localhost:8000/textAnalysis/index.html
Why This Project Needs That Path
This site uses a base path in the HTML:
<base href="/textAnalysis/">
Because of that, local testing works correctly only when:
- the server is started from the parent directory
- the page is opened through
/textAnalysis/index.html
If the server is started from inside the textAnalysis folder,
relative files such as pyscript.toml may fail to load correctly.
Typical Workflow
- Open the project folder in your code editor.
- Open a terminal in the folder above
textAnalysis. - Run
python -m http.server 8000. - Open
http://localhost:8000/textAnalysis/index.htmlin the browser. - Edit files.
- Save the file.
- Refresh the browser to see the changes.
Check if Python Is Installed
Open a terminal and run:
python --version
If that does not work, try:
python3 --version
If Python is installed, a version number should appear.
If Python Is Not Installed
If neither command works, Python may not be installed on your computer. Python is free and can be downloaded from the official Python website:
https://www.python.org/downloads/
On Windows, make sure to check Add Python to PATH during installation.
python command still does
not work, the usual cause is that Python was not added to PATH during installation.
Stopping the Server
Return to the terminal and press:
Ctrl + C
Example Terminal Session
cd your-parent-folder
python -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000...
The following example shows what a working session might look like:
Common Mistakes and Troubleshooting
Problem: the page loads, but some files fail with a 404 error
Make sure you:
- started the server from the folder above
textAnalysis - opened
http://localhost:8000/textAnalysis/index.html
Problem: you started the server from inside the wrong folder
The Python server serves files from the directory where it was started.
For this project, do not start it from inside
textAnalysis.
Use:
cd path/to/the/folder-above-textAnalysis
python -m http.server 8000
Problem: you opened the HTML file directly instead of using localhost
Do not open the file as:
file:///C:/.../index.html
Open it through the local server instead:
http://localhost:8000/textAnalysis/index.html
Problem: port 8000 is already in use
Use another port:
python -m http.server 8080
Then open:
http://localhost:8080/textAnalysis/index.html
About “Hot Reload”
This setup does not provide true hot reload. When you make changes to files, you will still need to refresh the browser manually to see updates.
That said, this workflow is still very useful because it lets the project run in a proper web environment and makes testing much faster than repeatedly uploading files to the live site.
Summary
Running a local Python server makes it easier to test changes safely before
uploading them to the live site. For this project, the key detail is to start
the server from the folder above textAnalysis and open the page
through:
http://localhost:8000/textAnalysis/index.html
