django显示文本字段 [英] django display textfields

查看:186
本文介绍了django显示文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django中有一个带有 textfield 的表单,用户逐行输入文本。
当我在admin端查看条目时,我确切地看到了用户的书写方式,但是当我在Django模板中将其显示在我的网站上时,它只是连接句子,而不能逐行显示文本



为了说明,用户输入文本为



-bla



-bla1



-bla2



但是,在我的页面中, / p>

-bla1-bla2-bla3



这是我在模板中的代码:

 < div> 
< p>
{{rev.myTextField}}
< / p>
< / div>


解决方案

在HTML中,文本之间的换行符并不表示显示换行符;您需要使用HTML插入换行符。最简单的方法是使用< br /> 标记,尽管还有其他方法。



Django为此有一个模板过滤器:使用 | linebreaks 此处是文档



因此,更改:

  {{rev.myTextField}} 

至:

  {{rev.myTextField |换行符} } 


I have a form with textfields in Django, and users enter texts line by line. When I look at the entries in admin side, I saw exactly how user wrote it but when I display it on my website, in Django templates, it just joins the sentences and I couldn't display the text line by line anymore.

To illustrate, user enters text as

-bla

-bla1

-bla2

However, it looks like in my page as

-bla1-bla2-bla3

This is my code in the template:

<div>
   <p>
      {{ rev.myTextField }}
   </p>
</div>

解决方案

In HTML, newlines between text don't imply a newline in display; you need to use HTML to insert the newline. The most straightforward way is with the <br /> tag, although there are other methods as well.

Django has a template filter for this: use |linebreaks. Here's the Documentation.

So, change:

{{ rev.myTextField }}

to:

{{ rev.myTextField|linebreaks }}

这篇关于django显示文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆