简体   繁体   中英

Using Markdown2 with Django

I have never asked a question here before, please bear with me. I am working on a wiki project that has a requirement to convert markdown files using markdown2.

    return render(request, "encyclopedia/entry.html", {
        "content": markdown2.markdown(util.get_entry(title)), "title": title
    })

Above is how I pass it to the HTML page and it renders on the page with the proper HTML tags, but it doesn't seem to use them. Below is how it appears on the browser.

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

         

I am passing it directly to a Django template with the safe filter included as shown below.

  <textarea name="content" rows="5" cols="50" readonly>
              {{ content|safe }}
         </textarea><br>

Thank you ahead of time, I hope I provided enough information to make my problem clear.

it looks like your content is going inside a <textarea> form field...that's going to prevent the browser from interpreting the HTML and just show exactly what is passed over.

Change to a <div> or something and it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM