【问题标题】:Adding linebreaks to string and then rendering linebreaks将换行符添加到字符串,然后渲染换行符
【发布时间】:2019-07-13 18:24:30
【问题描述】:

我正在尝试将换行符构建到字符串中,然后在带有换行符的模板中呈现该字符串。我将以下字符串保存到模型字段:

usercart.other_tax_regnum = "State tax reg number" + "/n" + "Second State tax reg number"  
usercart.save()

然后,在我看来,我渲染了该字段

 {{ usercart.other_tax_regnum|linebreaks }}

这不是显示换行符,而是呈现的内容:

State tax reg number/nSecond State tax reg number

有什么想法可以做到这一点吗?

谢谢!

【问题讨论】:

    标签: django


    【解决方案1】:

    你犯了一个小错误:

    右:

    \n
    

    错误:

    /n
    

    还有不同的方法:

    Take a look here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2019-12-05
      • 1970-01-01
      • 1970-01-01
      • 2022-11-17
      • 2019-10-10
      相关资源
      最近更新 更多