Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

html - How to print line breaks in Python Django template

{'quotes': u'Live before you die.

"Dream as if you'll live forever, live as if you'll die today"

"Love one person, take care of them until you die. You know, raise kids. Have a good life. Be a good friend. Try to be completely who you are, figure out what you personally love and go after it with everything you've got no matter how much it takes." -Angelina Jolie.'}

Notice my dictionary has line breaks in them:

How do I display my template with those line breaks?

{{quotes|withlinebreaks }}

question from:https://stackoverflow.com/questions/2316028/how-to-print-line-breaks-in-python-django-template

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the linebreaks filter.

For example:

{{ value|linebreaks }}

If value is Joel is a slug, the output will be <p>Joel<br />is a slug</p>.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...