I want to generate human-readable HTML and CSS code (properly indented) preprocessed by the Django template system for my standalone application.
I\'ve modified the
You could use class inheritance to create a different NodeList
but it will probably require some patching on a different end. Your solution seems plain and simple.
class MyNodeList(NodeList):
def render(self, context):
# call super if you require so
# your reindent functionality
Modifying the template layer would be ok, but not optimal, because it simply handles how a node is rendered, not an entire document. I would recommend writing custom middleware for your project to pretty-print the rendered response for html and css pages.
Your middleware will need to implement process_template_response
which should be used to view and update the SimpleTemplateResponse
object:
is_rendered
attribute to see if the response has been rendered.html
, .css
) at the end of the template_name
attributecontent_type
attribute (Django 1.5) or possibly mimetype
for older installsI think Middleware is a far more elegant solution because this ultimately makes no lexical changes to your files. It is entirely separated from the logic that determines your template content (where it has no business being). Finally, you want ALL of your html and css to look great, so why tie that to your templates in the first place?