Home


202512
Start webdev with Python, Apache and Docker


If you already know Python and have some basic familiarity with HTML and JavaScript (or you’re currently learning them), getting started with web development can still feel surprisingly hard. There are many platforms and frameworks that promise quick results, but they often hide what’s really going on under the hood.

In this tutorial, I want to show you a different approach: starting from simple, fundamental building blocks and gradually assembling them into fully fledged web applications.

This short introduction is meant to help you overcome the initial “steep hill” of web development—which, as you’ll soon discover, isn’t quite as steep as it first appears. Like any problem that seems complex at first glance, we’ll break it down into small, manageable pieces and tackle each challenge step by step.

1. Main idea and goal
Our goal is to build a very simple web application: a single web page with a button. When the button is clicked, a Python function is executed on the server, and the result—a plain text string—is sent back to the browser and displayed inside a
on the page.

We’ll call this app pwapp (short for Python web app). The server-side function will be intentionally simple: it will just return (or echo) the value of a parameter that we send to it.

def echo(self):
    message = self.pars.get("message", "no_message")
    return [self.return_string(message)]
To run Python code on a web server (Apache), we’ll use mod_wsgi. This module makes it possible to execute Python functions in response to web requests—such as those triggered by JavaScript running in the browser.

2. Software setup
We’ll do all development on your local machine. To keep the setup simple and avoid dependency issues, we’ll use Docker to install and run everything we need—Apache, mod_wsgi, Python, and a few additional tools. Installing Docker is the only prerequisite to follow along with this hands-on tutorial. All required files are already provided in the pwapp Github repository, which is structured as follows:
pwapp/
├── dbase/        # Docker base: folder with Dockerfile and setup files
│   └── venv/     # Python virtual environment created by Docker
│   └── logs/     # Apache logs
│   └── run/      # Apache and mod_wsgi pid and other files
├── web/          # Contains HTML, CSS, JS and other web files
└── pwapp/        # The actual WSGI app = Python package that is installed
To install everything, simply clone the GitHub repository, navigate to the dbase/ directory, and build the Docker image using build.sh. This step installs Apache and mod_wsgi inside the container and creates a Python virtual environment with all required packages listed in dbase/venv/requirements.txt.

3. Ready to go
You’re now ready to explore how everything fits together. Open your browser and visit http://localhost:8007, then start experimenting with index.html—especially the JavaScript functions attached to the buttons—and with index.py, where you can inspect and modify the echo function.

A concise 10-minute video tutorial that walks through this setup step by step is also available on YouTube:


Complete code available on pwapp Github.

Thanks for reading and if it was helpful to you, leave a comment below.

References