Reputation: 250
The Chinese words in my views.py causes a failure, when I remove those words it will be correct. These Chinese words only present in the print
sentence.
Is this a decode/encode problem? and how can I fix it?
When I vim
the views.py
in my server, it show the Chinese words incorrect. So I wonder maybe it is a decode/ecnode problem, am I right?
Upvotes: 1
Views: 96
Reputation: 250
I have solved this problem, which happened when I use such as ("%sxxx" % var)
grammer, then I change it to, ("%s%s" % (var, u'xxx'))
It works, hope it can help others
Upvotes: 1
Reputation: 473863
Add # -*- coding: utf-8 -*-
in the first line of your views.py
and mark your chinese strings as unicode by adding u
prefix.
Also see:
Upvotes: 2