【问题标题】:Django template filters - impossible to use urlize and textile chained togetherDjango模板过滤器 - 不可能使用链接在一起的urlize和textile
【发布时间】:2012-02-16 02:59:38
【问题描述】:

我发现无法使用链式过滤器 urlize 和 Textile。因为 urlize 过滤器是自动转义引号。另一方面,由于 Django 的建议,在纺织品输出后应用 urlize 是不可能的:

如果 urlize 应用于已经包含 HTML 标记的文本,事情 不会按预期工作。仅将此过滤器应用于纯文本。

任何过滤器序列都不起作用:

In [1]: from django.template import Template, Context
In [2]: text = '''"bla":/mo/14086/
   ...: http://bla.com'''
In [3]: Template('{% load markup %}{{ text|textile|urlize }}').render(Context({'text': text}))
Out[3]: u'\t<p><a href="/mo/14086/">bla</a><br />http://bla.com</p>'    
In [4]: Template('{% load markup %}{{ text|urlize|textile }}').render(Context({'text': text}))
Out[4]: u'\t<p>&quot;bla&quot;:/mo/14086/<br /><a href="http://bla.com" rel="nofollow">http://bla.com</a></p>'

有人知道如何同时使用这两个过滤器吗?

更新: 我正在使用 Django 版本 1.4 alpha 1 SVN-17347

【问题讨论】:

    标签: django django-templates django-template-filters


    【解决方案1】:

    with 的解决方法:

    {% with text|urlize as urlized %}
      {{ urlized|textile }}
    {% endwith %}
    

    【讨论】:

    • 没有帮助 - 与我的示例中的结果相同 - 行 Out[4]
    猜你喜欢
    • 2017-11-11
    • 2011-09-13
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    • 2018-05-04
    • 2015-06-18
    • 2016-05-20
    • 2014-09-28
    相关资源
    最近更新 更多