Django如何渲染markdown

本文已默认你已经好创建Django工程和App。

依赖包

pip install markdown django-markup bleach bleach-whitelist

示例代码

  • your_app/urls.py
urlpatterns = [
    path('about/', views.about, name="about"),
]
  • your_app/views.py
def about(request):
    content = ""
    with open("./templates/license.md", 'r') as f:
        content = formatter(f.read(), filter_name="markdown")
    return render(request, 'about.html', {"content":content})
  • templates/about.html
    {% load markup_tags %}
    {{ content|apply_markup:"markdown" }}


MARSGGBO原创





2019-9-3



posted @ 2019-09-03 09:34  marsggbo  阅读(799)  评论(0编辑  收藏  举报