Python task manager from scratch, part 17: Generating some HTML

Last time I mentioned that we had two related issues to fix:

  1. What we were displaying as HTML was not in fact valid HTML;
  2. The code generating that "HTML" from a list of tasks was the least-tested part of Veery.

Steps to fixing those problems

  1. Create a folder, and a file in that folder, for functions we write to generate HTML.
  2. Test that function.
  3. As we test that function, realize that we're generating a list of dummy tasks over and over in our tests.
  4. Factor out that generation into a test fixture. Put it in
  5. Run Pytest to make sure that all our tests still pass.

Other notes

  1. This tutorial diverges from others (in many ways but markedly) in not using a templating engine to generate HTML for you. I'm doing this for a few reasons. First, I want to avoid dependencies. Second, I want you to understand that templating engines are string-generation (or file-generation) tools in fancy clothing. Third, I generally find templating engines frustrating to use. Fourth, when I was first learning Web development, I believe the templating stuff took up a lot of short-term memory for relatively little conceptual payoff. If we really need a templating engine later, we can always add that dependency. (As long as we behave responsibly between now and then and keep HTML-generation code cleanly separated and logically structured. Which we will.)
  2. The test we have for the template is not sophisticated; it is just a basic "smoke test." We can always supplement it with manual checks or fancy front-end testing tools if we like. Note that this test will catch many errors that actually occur, and is annoying or impossible to write with a templating engine.

Here's the current commit in the veery/ repository.

Next post: Python task manager from scratch, part 18: Adding a feature

Home page