gpt4 book ai didi

python - 在 Django 中使用 Markdown2

转载 作者:行者123 更新时间:2023-12-04 12:58:26 25 4
gpt4 key购买 nike

我以前从未在这里问过问题,请耐心等待。我正在处理一个需要使用 markdown2 转换 Markdown 文件的 wiki 项目。

    return render(request, "encyclopedia/entry.html", {
"content": markdown2.markdown(util.get_entry(title)), "title": title
})
上面是我如何将它传递给 HTML 页面并使用正确的 HTML 标签在页面上呈现,但它似乎没有使用它们。下面是它在浏览器上的显示方式。
              <pre><code>      # HTML
</code></pre>

<p>HTML is a markup language that can be used to define the structure of a web page. HTML elements include</p>

<ul>
<li>headings</li>
<li>paragraphs</li>
<li>lists</li>
<li>links</li>
<li>and more!
most recent major version of HTML is HTML5.</li>
</ul>


我将它直接传递给包含安全过滤器的 Django 模板,如下所示。
  <textarea name="content" rows="5" cols="50" readonly>
{{ content|safe }}
</textarea><br>
提前谢谢你,我希望我提供了足够的信息来澄清我的问题。

最佳答案

看起来您的内容进入 <textarea>表单字段...这将阻止浏览器解释 HTML 并准确显示传递的内容。
更改为 <div>或某事,它应该工作。

关于python - 在 Django 中使用 Markdown2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62855513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com