【问题标题】:can't encode single quote (') using django's render_to_string无法使用 django 的 render_to_string 对单引号 (') 进行编码
【发布时间】:2011-04-29 17:24:54
【问题描述】:

我对 django 的 render_to_string 和编码单引号有问题。

... = render_to_string('dummy.txt', {'request':request, 'text':text,}, context_instance=RequestContext(request)))

为什么只有这些引号被翻译成 '#39;'和所有其他特殊字符不是吗?

【问题讨论】:

  • 您能提供一些输入/输出吗? dummy.txt 可能吗?

标签: django unicode quotes render-to-string


【解决方案1】:

要获得纯字母的字符串,您需要对其进行转义。 在模板标签中自动转义您的变量。 像这样的

{% autoescape off %}
{{ body }}
{% endautoescape %}

【讨论】:

  • 是的,这是丹尼尔 10 年前就已经回答的问题了。 ;)
  • 以防万一有人正在寻找快速复制粘贴解决方案。 :-)
【解决方案2】:
猜你喜欢
  • 2010-10-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-30
  • 2017-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多