CPT
CPT

Reputation: 250

Chinese in views.py cause failure

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

Answers (3)

Dominic
Dominic

Reputation: 19

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

Upvotes: 1

CPT
CPT

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

alecxe
alecxe

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

Related Questions