Reputation: 627
I want to make two changes to the text that is displayed in my Django template. First, I want to strip the text of any HTML. The following code works for me:
{{ article.abstract|striptags }}
Second, I want to replace all instances of \n
with <br />
I tried:
{{ article.abstract|striptags|replace('\n', '<br />') }}
That gave me an invalid filter error. I even tried:
{{ article.abstract|striptags|replace('\n', '') }}
That did not work either. Are there any suggestions? Thank you.
Upvotes: 0
Views: 821
Reputation: 1555
For your first problem (removing html from output), striptags
is a good choice.
For your second problem (converting \n
to newlines), check out the linebreaks filter. Actually, in your case, linebreaksbr might be a better choice.
Your code would look like this:
{{ article.abstract|striptags|linebreaksbr }}
Upvotes: 2