[Answered ]-Django templates and markdown


Since what you are generating from the Markdown-formatted content is a Django template it makes the most sense to use your first method (generate HTML from the Markdown template and then use the generated Django template in a loop).

As well as being faster, that also ensures that nothing in obj is accidentally translated into HTML by Markdown.

I would also “cache” the Django template:

template_content_html = markdown.markdown(template_content_md)
# Only generate the template once
tt = template.Template(template_content_html)

for obj in object_list:
    content_html = tt.render(Context({'obj': obj}))

Leave a comment