1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonというかDjangoで Markdownの表

Last updated at Posted at 2019-06-23

Djangoを使っていて,Markdownで表を書くときのメモ.

要は,extensions=['tables']を指定するということ.
これを指定しないと,Markdownで表を書いても<p>....</p> でレンダリングされる.

markdown.py
from markdown import Markdown
from django.utils.html import mark_safe

class MarkDownView(TemplateView):                                                            
    template_name = 'myapp/markdown.html'

    def get(self,request,*args,**kwargs):
        mdsrc = '.....some mark down text including a table.....'

        md = Markdown(extensions=['tables'])
        md_html = mark_safe(md.convert(mdsrc))

        self.extra_context = { 'md_html': md_html , }
    return super().get(request,*args,**kwargs)

テンプレート側では,お約束でsafeを指定します.

myapp/markdown.html
         :
    {{ md_html|safe }}
         :

他のextensionsについては下記.

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?