markdown in django template

  1. enter
pip install markdown pygments
  1. For example,

    • model named Blog

    • markdown field name content

    • class based view

def get_content_data(self, **kwargs):
 md = markdown.Markdown(extensions=['fenced_code'])
 context = super().get_context_data(**kwargs)
 context['object'].content = md.convert(self.object.content)
 return context

in template

{{ object.content | safe }}