[英]How to render markdown file to HTML using django?
I am trying to render a page that written in markdown to HTML when clicking a link using Django.当单击使用 Django 的链接时,我试图将用Markdown编写的页面呈现为 HTML。
but every time I click on the link the markdown page does not render will但每次我点击链接时,降价页面不会呈现
here's my views.py :这是我的views.py :
from django.shortcuts import render
from . import util
def index(request):
return render(request, "encyclopedia/index.html", {
"entries": util.list_entries()
})
def search(request, name):
return render(request, f"{ name }.md")
and here's the urls.py :这是urls.py :
from django.urls import path
from . import views
urlpatterns = [
path("", views.index, name="index"),
path("<str:name>", views.search, name="search")
]
只需将 MARKDOWN 转换为您自己的 HTML,这是最简单的方法
I would suggest converting the file beforehand.我建议事先转换文件。 If you really need to do it at runtime, you can simply use a package to convert the file to HTML and then point to the rendered file.
如果你真的需要在运行时做,你可以简单地使用一个包将文件转换为 HTML,然后指向渲染的文件。 Pypandoc can achieve this and probably many other python packages
Pypandoc 可以实现这一点,可能还有许多其他 python 包
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.