python - Problem with encoding in Django templates -


There is a problem using {% ifequal s1 "some text"%} to compare strings with extended characters in the Django template. I

127 in string S1, I get an exception in template rendering. What am I doing wrong? I am using UTF-8 coding in the rest of the application in both the data, templates and the Python code without any problem.

views.py

  DIF test (request): Return render_to_response ("test.html", {"s1": "dados", "s2": "aprovação ",})  

test.html

  S1 = {{S1}} & lt; Br> S2 = {{s2}} & lt; Br> {% Ifequal s1 "dados"%} s1 = "dados" is true {% endifequal%} {% compound s1 "aprovação"%} s1 = "aprovação" is true {% endifequal%} {% Comment%} The following two synchronization The following exception is caused: An exception was caught while rendering: 'ASCI' codec can not decode byte 0xc3 in position 6: not in serial number (128) {% ifequal s2 "dados"%} s2 = "dados "True {% endifequal%} {% ifequal s2" aprovação "%} s2 =" aprovação "is true {% endifequal%} {% endcomment%} {% unusual s2 u" dados "%} s2 =" dados "true The following exception has caused the following exception {% endifequal%} {% comment%} Exception: The exception was caught while rendering: 'ascii' can not encode characters in codec position 8-9: in non sequential order (128) {% ifequal s2 u "aprovação"%} S2 = "aprovação" is true {% Endifequal%} {% endcomment%}  

output

  s1 = dados s2 = aprovação s1 = "dados" is true  < / Pre> 

Sontemi S has nothing to help you solve any other problem. :) I should have marked the Python string as Unicode in this way and now everything now works:

  def test (request): return render_to_response ("test.html",) {"S1": u "Dados", "s2": u "aprovação",})  

Comments