I’m working on a personal project using Django to help me learn the framework better. I’ve implemented a bunch of custom commands so I can conveniently interact with my models and perform related tasks from the command line. I’ve developed a bunch of code that displays the contents of my models with an increasing amount effort going into layout and style. I’d like to refactor that code using a template-based approach, but after several hours of searching the web, I can’t find any commentary or prior art about this specific use case.
Here’s what I’ve cobbled together so far:
- I know how to create templates and use django.template.loader.render_to_string to load and render them.
- I know how to access django.utils.termcolors and use colorize() and make_style() to apply color to output. (not documented, found it in the source)
- I know how to create and register a custom template filter that applies color to the input, and load and use it in my template.
I could proceed with a solution built on these pieces, but I wanted to ask experienced people:
- Am I do anything stupid, or is all of the above reasonable / optimal?
- Is there really no existing solution for this, like a template engine specifically for producing output for terminals, and addressing things like detecting terminal width and padding values with whitespace for complex layouts?