Tuesday, May 8, 2012

django.http.HttpResponse does not deal unicode properly

following Tutorial 3, I have written this trivial views.py:



# coding = UTF-8
from django.http import HttpResponse

def index(request):
return HttpResponse( u"Seznam kontakt?" )


I tried also other tricks, such as using django.utils.encoding.smart_unicode(...), the u"%s" % ... trick, etc.



Whatever I try, I always get "Non-ASCII character" error:



SyntaxError at /kontakty/

Non-ASCII character '\xc5' in file C:\Users\JindrichVavruska\eclipse\workspace\ars\src\ars_site\party\views.py
on line 5, but no encoding declared;
see http://www.python.org/peps/pep-0263.html for details (views.py, line 5)


It is even more mysterious because I used a lot of national character strings in other files, such as models.py, e.g. text = models.CharField( u"VÅ¡echen text", max_length = 150), and there was absolutely no problem at all.



I found other answers on this site irrelevant, the suggested changes make no difference in my views.py



Jindra





No comments:

Post a Comment