Member-only story
Using Python to create static web pages — the easy way!
Substituting data into a text template using Python and Jinja2. This can be used for document, report and script generation — as well as static HTML pages.
Introduction and Aims
For the purpose of this article, I wish to create web page summarising all my Medium articles. I start with a list of Titles, Subtitles and URLs and convert them into a static HTML page for viewing on my personal GitHub.io site.
This can be done in one of three ways:
- Manual Copy, Paste and Edit — too time-consuming
- Python string formatting — excessively complex
- Using the Jinja templating language for Python — the aim of this article
Side Note: It is possible to accomplish the same task using Flask, however render_template
already uses Jinja2 under the hood and we do not want the additional requirement of needing a webserver — so we ignore this solution.
The Copy Paste Method
This is probably the most widely used, but least efficient method. For a small number of files, this can be a quick and easy implementation, however, with >10 data points…