How can display the lines from linux log file in b

2019-08-25 06:47发布

I am getting the lines from the linux log files and i am displaying in the bowser using django.

  1. They are all displaying as same paragarah but i want to show them with new lines
  2. They display in nelwines if i warp them in <pre> lines </pre> but then my html tags are not rendered properly

is there any way to display that in good format with newlines and html tag rendered properly

3条回答
smile是对你的礼貌
2楼-- · 2019-08-25 06:48

You can try to convert newlines to <br /> tags

There is a Django filter that can be useful https://docs.djangoproject.com/en/dev/ref/templates/builtins/#linebreaks

{{ value|linebreaks }}
查看更多
女痞
3楼-- · 2019-08-25 07:01

Try using linebreaks or linebreakbr filters. From django reference

linebreaks
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an 
HTML line break (<br />) and a new line followed by a blank line becomes a paragraph 
break (</p>).

For example:

{{ value|linebreaks }}
  If value is Joel\nis a slug, the output will be <p>Joel<br />is a slug</p>.

You can also use linenumbers

查看更多
beautiful°
4楼-- · 2019-08-25 07:15

You can use built-in template tags:

{{ lines|linebreaks }}

or

{{ lines|linebreaksbr }}
查看更多
登录 后发表回答