문제

I'd like to display the content of a file file1 link to one of my object object1.

In my view, I added object1 to the context. In my django template, I used:

<html> [...]
{{ object1.file1.read }}
[...]
</html>

This works perfectly but let's say my file is like this:

Lorem ipsum \n
\n
This is a pretty stupid SO question, sorry\n
foo bar

It's rendered in only one line. \n are not interpreted. What should I do? Is there some tag/filter/blackmagic I could add to do so? Moreover, what kind of characters will be eluded using {{ file.read }} to be less specific ?

Cheers guyz

도움이 되었습니까?

해결책

Use the linebreaksbr filter like this:

{{ object1.file1.read|linebreaksbr }}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top