Foxjack
Foxjack

Reputation: 117

How to filter the html markups when render a template with jinja2?

Now I'm biulding a django project with jinja2 dealing with templates. Some page contents are submited by the client with wysiwy editor, and thing's going fine with the detail pages.

But the list pages are wrong with the slice of the contents.

My code:

<div class="summary ">
     <div class="content">{{ question.content[:200]|e}}...</div> 
</div>

But the output is:

<p>what i want to show here &nbsp;is raw text without markups</p>...

The expected result is that the html markups like <p></p> <section>.... are gone (filtered or eliminated) and only the raw text shows!

So how can I fix it? Thanks in advance!

Upvotes: 4

Views: 6062

Answers (1)

alecxe
alecxe

Reputation: 473863

Use striptags filter:

striptags(value)

Strip SGML/XML tags and replace adjacent whitespace by one space.

<div class="content">{{ question.content|striptags}}...</div> 

Jinja2 striptags filter test will also help you to understand how it works.

Hope that helps.

Upvotes: 13

Related Questions