Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:43:04+00:00 2026-05-25T01:43:04+00:00

Suppose I have a Django template written in Markdown. Does it make sense to

  • 0

Suppose I have a Django template written in Markdown.

Does it make sense to process the markdown first, and then render the template, or should I render the template, and then send it through the Markdown filter?

From a computation standpoint the first is preferable, as I’m going to be rendering the template in a loop. I’m just wondering if there are some possible drawbacks I’m not thinking of.

Some code for reference:

import markdown
from django import template

# Here, template_content_md would actually come from the database
template_content_md = """
{{ obj.title }}
-----------
**{{ obj.author }}**

(more Markdown content here using variables)

[More info]({{ obj.get_absolute_url }})
"""

output_list = []

# first method
template_content_html = markdown.markdown(template_content_md)
for obj in object_list:
    tt = template.Template(template_content_html)
    content_html = tt.render(Context({'obj': obj}))
    output_list.append(content_html)

#second method
for obj in object_list:
    tt = template.Template(template_content_md)
    content_md = tt.render(Context({'obj': obj}))
    content_html = markdown.markdown(content_md)
    output_list.append(content_html)

As you can see, in the second version, markdown.markdown is run once for each obj in object_list.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:43:04+00:00Added an answer on May 25, 2026 at 1:43 am

    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}))
        output_list.append(content_html)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two applications written in C#. The first is a third party
Suppose you have a Django view that has two functions: The first function renders
Suppose I have a stringbuilder in C# that does this: StringBuilder sb = new
suppose we have a model in django defined as follows: class Literal: name =
Suppose I have the following Event model: from django.db import models import datetime class
This question relates to Django Aggregation/Annotation in 1.1. Suppose I have a simple model
I've got a problem with using django's {% trans %} template function. I have
Suppose I have a Django app named blog. There's a model called Post and
Suppose I have a Django model as follows: class Person(models.Model): first_name = models.CharField(max_length=50) last_name
I currently have a very simple web application written in Django, and I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.