मैं {% ifequal एस 1 "कुछ पाठ"%} का उपयोग कर Django टेम्पलेट्स में विस्तारित पात्रों के साथ तार की तुलना करने में समस्या आ रही। स्ट्रिंग एस 1 ASCII वर्ण> 127 शामिल हो, तब मैं टेम्पलेट प्रतिपादन में अपवाद मिलता है। मैं क्या गलत कर रहा हूं? मैं दोनों डेटा, टेम्पलेट्स और अजगर कोड में आवेदन के बाकी भर में UTF-8 कोडिंग का उपयोग कर रहा बिना किसी समस्या के।समस्या टेम्पलेट्स
views.py
def test(request):
return render_to_response("test.html", {
"s1": "dados",
"s2": "aprovação",
}
)
test.html
s1={{s1}}<br>
s2={{s2}}<br>
{% ifequal s1 "dados" %}
s1="dados" is true
{% endifequal %}
{% ifequal s1 "aprovação" %}
s1="aprovação" is true
{% endifequal %}
{% comment %}
The following two comparions cause the following exception:
Caught an exception while rendering: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)
{% ifequal s2 "dados" %}
s2="dados" is true
{% endifequal %}
{% ifequal s2 "aprovação" %}
s2="aprovação" is true
{% endifequal %}
{% endcomment %}
{% ifequal s2 u"dados" %}
s2="dados" is true
{% endifequal %}
{% comment %}
The following comparison causes the following exception:
Caught an exception while rendering: 'ascii' codec can't encode characters in position 8-9: ordinal not in range(128)
{% ifequal s2 u"aprovação" %}
s2="aprovação" is true
{% endifequal %}
{% endcomment %}
आउटपुट
s1=dados
s2=aprovação
s1="dados" is true