django 转义标签不转义单引号
django escape tag not escaping single quotation marks
我正在使用 django 1.7。
当用户输入单 and/or 双引号作为其输入的一部分时,显示其输入数据的表单将被破坏。
所以我使用了django的escape标签,应该很容易处理这个问题。
但是,escape 标签只是转义了双引号。单引号没有被转义,破坏了测试形式。
这是我的代码示例:
{{ field|escape }}
有谁知道如何解决这个问题。
编辑
这是我的表单字段模板代码 (form_fields.html):
<div id="row_{{ field.auto_id }}" class="form-group {% if field.errors %}error{% endif %} {% if hide_row %}hidden{% endif %}">
<label for="{{ field.auto_id }}" class="control-label {{ field.css_classes }}">
{{ field.label }}{% if field.label %}:{% endif %}
</label>
<div class="controls {{ control_classes }}">
{{ field|escape }}
{% if field.errors %}
<span class="help-inline">
<strong>
{% for e in field.errors %}
{{ e }}<br/>
{% endfor %}
</strong>
</span>
{% endif %}
{% if field.help_text %}
<p class="help-block">
{{ field.help_text }}
</p>
{% endif %}
</div>
</div>
这里是表单模板字段代码:
{% load form_fields %}
....
{% form_field form.name_details_prefix_title %}
我最终将错误跟踪到 js 问题。
我使用了以下标签来解决问题:
{{ field|escapejs }}
希望这对某些人有所帮助。
我正在使用 django 1.7。
当用户输入单 and/or 双引号作为其输入的一部分时,显示其输入数据的表单将被破坏。
所以我使用了django的escape标签,应该很容易处理这个问题。
但是,escape 标签只是转义了双引号。单引号没有被转义,破坏了测试形式。
这是我的代码示例:
{{ field|escape }}
有谁知道如何解决这个问题。
编辑
这是我的表单字段模板代码 (form_fields.html):
<div id="row_{{ field.auto_id }}" class="form-group {% if field.errors %}error{% endif %} {% if hide_row %}hidden{% endif %}">
<label for="{{ field.auto_id }}" class="control-label {{ field.css_classes }}">
{{ field.label }}{% if field.label %}:{% endif %}
</label>
<div class="controls {{ control_classes }}">
{{ field|escape }}
{% if field.errors %}
<span class="help-inline">
<strong>
{% for e in field.errors %}
{{ e }}<br/>
{% endfor %}
</strong>
</span>
{% endif %}
{% if field.help_text %}
<p class="help-block">
{{ field.help_text }}
</p>
{% endif %}
</div>
</div>
这里是表单模板字段代码:
{% load form_fields %}
....
{% form_field form.name_details_prefix_title %}
我最终将错误跟踪到 js 问题。
我使用了以下标签来解决问题:
{{ field|escapejs }}
希望这对某些人有所帮助。