2008年11月5日 星期三

Django的escape

由於 escape 通常都會大量的使用,因此在Django 1.0 的 template 中,已經不需要設置 filter escape 了,因為它已經是預設值了

所以又多了一個 on/off 功能..

這樣才會停止 escape 的功能
{% autoescape off %}
    {{ variable }}
{% endautoescape %}


當然也可以這樣使用,variable1 將會停用 escape 功能,variable2 就啟用 escape 功能
{% autoescape off %}
    {{ variable1 }}
    {% autoescape on %}
        {{ variable2 }}
    {% endautoescape %}
{% endautoescape %}


這樣子也會啟用
{% autoescape off %}
    {{ variable|escape }}
{% endautoescape %}

沒有留言: