Code Maven

Search for '{{search_term}}'

Welcome to the Code Maven!

Programming Exercises for any language.

If you want to make sure you don't miss any new articles, you can subscribe to the Code Maven newsletter, follow via atom feed or Twitter

Skeleton: A minimal example generating HTML with Python Jinja

Jinja is a templating system usually used together with the Flask web framework, but it can also be used separately. I often start projects generating some static HTML files based on some data in JSON file as was the case in the Code And Talk project. In other cases data is taken from a database, but I might still start by generating a few static HTML pages.

Every time though I have to spend some time figuring out how to lay out my files and how to load the template. So here is an example that you can also use as a skeleton for your next application.


Skeleton: A minimal example generating HTML with Python Jinja


Python: Temporary files and directory for Pytest

When we write tests for complex applications, the application will often rely on some files that ned to be read. For example configuration files.

In addition the application might create files while the test is running or change some of the existing files.

We would like to be sure these changes don't interfer with the regular work of the rest of the computer and even if we run several tets in parallel that might all want to change the same file, these tests won't interfer with each other.

The best course of action for us is to use a unique temporary directory for each test function.


Python: Temporary files and directory for Pytest