【问题标题】:I can not use django template-tag linebreak and justify我不能使用 django template-tag linebreak 和 justify
【发布时间】:2020-03-21 16:59:53
【问题描述】:

我尝试证明我从数据库中获取的一些文本,但我还需要使用模板标签换行符。

html:

<p class="justify">{{ article.contenu|linebreaks }}</p>

css:

.justify
{
    text-align: justify!important;
}

除非我删除换行标记,否则我的文本将无法证明自己的正确性。

知道如何同时使用 justify 和 linebreak 标签吗?

真诚的

【问题讨论】:

    标签: css django django-templates justify templatetags


    【解决方案1】:

    使用这个 Django 过滤器:

    <p class="justify">{{ article.contenu|linebreaksbr }}</p>
    

    希望对你有帮助,谢谢。

    【讨论】:

      【解决方案2】:

      在模板中,你应该使用安全的模板标签:

      <p class="justify">{{ article.contenu|safe }}</p>
      

      如果需要,您也可以在linebreaks 之前使用safe

      <p class="justify">{{ article.contenu|safe|linebreaks }}</p>
      

      【讨论】:

      • 感谢您的回复,但添加标签 safe 对我没有帮助。顺便说一句,自动转义没有关闭。
      猜你喜欢
      • 2019-11-23
      • 2021-02-28
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多