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" }}