依赖包
代码语言:javascript复制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" }}