I'm a student in Kazakhstan, and I built a free course for people who have never written a line of code. It goes from print() to a to-do app in Flask or Django and then puts it online. No sign-up, nothing to install, and it's in English, Russian and Kazakh.

The site is plain HTML, CSS and JavaScript on GitHub Pages. There is no backend. Still, Python runs right on the page, exercises check themselves, and you can click through the Flask app from the course before you install anything.

Here's how it works, plus a few things I learned along the way.

Site: pywebguide.github.io/en · Code: GitHub (MIT)

What's inside

  • 13 Python lessons for complete beginners, every example has a Run button
  • 78 exercises with automatic checking, hints and solutions
  • How a website works: requests and routes, templates and forms, SQL, sign-in, REST APIs, tests, Git
  • A first project, a to-do list in Flask or Django, step by step, with the terminal output and a .zip of the code after every step
  • More projects: a blog API in Flask, relations and class-based views in Django, a first API in FastAPI, then deploying to PythonAnywhere

Python in the browser: Pyodide in a Web Worker

Python comes from Pyodide, CPython compiled to WebAssembly. The core is about 5 MB, so nothing loads until the learner presses Run for the first time.

It runs in a Web Worker. On the main thread, a beginner's first while True: would freeze the whole tab. I didn't want a separate worker file, so the worker source is a string turned into a Blob:

const WORKER_SOURCE = [ 'importScripts("' + PYODIDE + 'pyodide.js");', 'const ready = loadPyodide({ indexURL: "' + PYODIDE + '" });', // ... onmessage: run the learner's code, post output back ].join("\n"); const url = URL.createObjectURL(new Blob([WORKER_SOURCE], { type: "text/javascript" })); worker = new Worker(url); 

Output is streamed back in messages, so a long loop prints as it goes, not all at the end.

Infinite loops vs. GitHub Pages

Pyodide can interrupt running code through a SharedArrayBuffer. But that only works on cross-origin isolated pages, which need the Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy headers. GitHub Pages doesn't let you set headers.

So the solution is blunt, and it works:

// starts once packages are loaded and the learner's code is running timer = setTimeout(function () { worker.terminate(); worker = null; // a fresh worker is created on the next Run finish({ ok: false, error: "The code ran for more than 10 seconds and was stopped. It may contain an endless loop." }); }, 10000); 

After a stop, Python loads again, but from the browser cache, so it's quick. For exercises that finish in milliseconds, it's a fine trade-off.

Errors in plain words

A Python traceback scares a beginner more than the bug does. So errors go through a table of a few dozen patterns, each a regex for the last line of the traceback plus an explanation:

[/^TemplateNotFound: (.+)$/, "Flask could not find the template {x}. The file must be in the templates folder next to app.py, ..."], 

The traceback is still shown, but trimmed to the learner's own code. In CI, a script triggers every error in the table with real Python and checks that the pattern still matches and that the explanation exists in all three languages.

Flask without a server

This is my favorite part. In the first project, learners can try the finished Flask to-do app right on the page.

Flask isn't part of the Pyodide distribution, but it's pure Python, so micropip installs it on the first import flask. With Python it comes to about 15 MB, and the "Try it in the browser" button says so.

There's no socket in a browser. Flask has test_client, though, which sends a request through the whole app — routes, Jinja templates, redirect, url_for, form handling — without a network. The app code runs once in its own namespace and stays alive between requests, so added tasks don't disappear:

# runs in the worker for every request from the mini-browser __r = __client.open(__req["path"], method=__req["method"], data=__req.get("form") or None) {"status": __r.status_code, "location": __r.headers.get("Location"), "type": __r.content_type, "body": __r.get_data(as_text=True)} 

The page draws a small browser window: an address bar showing 127.0.0.1:5000, a Back button and an <iframe sandbox="allow-same-origin allow-forms">. The Flask response goes into srcdoc. Links and form submissions inside the iframe are intercepted and become requests to the worker. When Flask answers with a redirect, which it always does after a POST in the project, the mini-browser follows it like a real one and shows the chain under the window: POST /add → 302, GET / → 200.

In the SQLite step, the database lives in Pyodide's in-memory file system. The worker sets __file__ for the app, so the course code works unchanged.

To be clear, this is not a server in the browser. It's real Flask with requests handed to it directly. For learning the form → POST → redirect → GET loop, that's enough, and learners still install Python later. The course walks them through that.

A tutorial that tests itself

The worst thing a tutorial can do is show output that doesn't match what the learner sees. So nothing gets deployed unless CI is green, and CI goes through the tutorial the way a learner would:

  • Every runnable example is executed with real Python in all three languages (126 runs). Every other Python block gets a syntax check.
  • Every exercise is checked against its reference solution by the same checker.py the browser uses.
  • The Django and FastAPI projects are replayed step by step in real projects. Files come from the code blocks, commands from the "Terminal" blocks, and the output is compared with the "Expected result" on the page. The manage.py shell session is typed line by line, so the transcript on the page matches a real one:
console = code.InteractiveConsole(namespace) # same auto-imports as manage.py shell for line in open(LINES, encoding="utf-8").read().splitlines(): print(("... " if more else ">>> ") + line) more = console.push(line) 
  • The .zip after every step is built from the page, and CI unpacks each one and runs it. The zips are byte-for-byte reproducible (fixed timestamps, stable order), so git never shows noise diffs.

Three languages from one source

The Russian pages are the source. The Kazakh and English pages are built by a script from translation memories, fragment by fragment, and a test makes sure the translation keeps the original markup. Code samples, terminal output, screenshots and the downloadable zips are translated too, and the translated code goes through the same CI.

Kazakh brought a couple of surprises:

  • Fonts. The display font has no Kazakh letters (ә, ғ, қ, ң, ө, ұ, ү, һ, і), so Kazakh pages use a different one for headings, both on the site and on the social preview images.
  • Sorting. A Django model sorts categories by name. In Russian, "Дом" (Home) comes before "Учёба" (Study). In Kazakh, "Оқу" (Study, О = U+041E) comes before "Үй" (Home, Ү = U+04AE). The order in Category.objects.all() and in the drop-down flipped. CI compares the output on the page with a real run, so it can't drift.

One page was too heavy

Lighthouse on mobile showed one page lagging behind: "Python from scratch" had 13 lessons, 4 mini-projects and 28 exercises on a single page. That's over 3,000 elements, and the first screen waited for the browser to lay out all of them.

I first tried content-visibility: auto on the lessons. It barely moved the numbers, and it would have broken the code block's full-screen mode (position: fixed inside a contained element), so I reverted it. The real fix was to split the course into four pages of about 900 elements each. Progress is stored under the same key, so nobody lost their checkmarks, and old links like start.html#lesson-7 redirect to the right part.

Limitations

  • First load is heavy: about 5 MB for Python and about 15 MB with Flask. That's why nothing loads until you press Run.
  • It depends on a CDN. Pyodide comes from jsDelivr. If that's blocked, Python won't start, but the rest of the course still works.
  • It's not a real server, as above.
  • Translations: the Kazakh and English versions were translated with AI help. If you're a native speaker and something reads oddly, an issue would be very welcome.

Feedback welcome

I'd love feedback, especially from people who teach programming or are just starting out. Where would a beginner get stuck? What's missing?