我正在使用django 1.7。
当用户输入单引号和/或双引号作为其输入的一部分时,显示其输入数据的表单会出现错误。
因此,我使用了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 %}
escape
过滤器来转义整个字段,你只能对值进行操作,但这应该是自动工作的。请展示你的表单类。 - GwynBleidD