2015-10-10 27 views
1

我正在使用django 1.7。django escape tag不能轉義單引號

當用戶輸入單引號和/或雙引號作爲其輸入的一部分時,顯示其輸入數據的表單被打破。

因此,我用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 %} 
+1

你能舉一些例子嗎?你的表單,字段和一些模板代碼重新創建? – GwynBleidD

+0

GwybBleidD - 根據要求添加代碼。 – user1261774

+0

你不能用'escape'過濾器來清除整個字段,你應該只用值來做,但是這應該是自動工作的。請出示您的表格課程。 – GwynBleidD

回答

2

我最終跟蹤第j個問題的錯誤。

我用下面的標籤來解決這個問題:

{{ field|escapejs }} 

希望這可以幫助其他人。