1

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?

CPT
  • 250
  • 1
  • 12

3 Answers3

2

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:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

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

Chris
  • 8,527
  • 10
  • 34
  • 51
CPT
  • 250
  • 1
  • 12
1

use such as : ("%s%s" % (var, u'xxx'))

Dominic
  • 19
  • 3