Django似乎逃脱了HTML字符(但不应该)

时间:2016-07-21 09:25:16

标签: python django localization translation

将Django从1.8升级到1.9.8(并在此过程中升级了一堆模块)后,我的模板中的翻译出现了问题。

使用 '# PURPOSE: Process multi-area range Dim rngArea As Range ' Single area in multi-area selection Dim lngCol As Long ' Column in selected range(area), 1 based Dim lngRow As Long ' Row in selected range(area), 1 based Dim avarValues As Variant ' 2D variant array for range(area) values, 1 based ' --> Add validation here <-- ' Go through each area in selected range ' -------------------------------------- For Each rngArea In rng.Areas ' Store the values into 2d array (Row, Column), 1 based avarValues = rngArea ' Show each value held in the array For lngRow = 1 To UBound(avarValues, 1) For lngCol = 1 To UBound(avarValues, 2) ' Note row / column index is NOT necessarily the same as the row/column on the worksheet ' Index 1 will be the first cell in the selected area Debug.Print "Area " + rngArea.Address + ", value in AREA row " & lngRow & ", column " & lngCol & ": " & avarValues(lngRow, lngCol) Next lngCol Next lngRow Next rng End Function 字符串与Foobar字符串相关联,代码为:

foo<br>bar

在升级之前工作得很好,显示:

<p>{% i18n 'Foobar' %}</p>

但现在,它显示:

foo
bar

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

好的,感谢Bestasttung的评论,我解决了我的问题:

{% autoescape off %}
<p>{% i18n 'Foobar' %}</p>
{% endautoescape %}

但这并不令人满意,因为我有多个模板需要更新。 所以,我只是改变了我的i18n方法:

def i18n(context, key):
    ...
    return s

为:

def i18n(context, key):
    ...
    return mark_safe(s)

我希望这能帮助面临同样问题的人。