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.

Daniel Ellis Research
Towards Data Science
6 min readNov 23, 2020

--

A strip of images from medium articles, created through the methods described in this article
Source: wolfiex.github.io/medium (self)

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…

--

--

Towards Data Science
Towards Data Science

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Daniel Ellis Research
Daniel Ellis Research

Written by Daniel Ellis Research

Research Software Engineer specialising in High-Performance Computing and Data Visualisation. — PhD in Atmospheric Chemistry and Masters in Theoretical Physics.

No responses yet