manage.py syncdb error while Django model using non-ascii verbose_name
I am pretty new to Django.
I want the name of my models to be displayed in Chinese, so i used verbose_name in my meta class of my model, codes below:
#this models.py file is encoded in unicode
class TS_zone(models.Model):
index = models.IntegerField()
zone_name = models.CharField(max_length=50);
zone_icon = models.ImageField(upload_to='zone_icon', null=True)
is_active = models.NullBooleanField(blank=True, null=True)
status = models.CharField(max_length=7,choices=SETTING_STATUS_CHOICES)
class Meta:
ordering = ('index',)
verbose_name = u'你好嗎?'
verbose_name_plural = u'你們都好嗎?'
def __unicode__(self):
return self.zone_name
However when i run manage.py syncdb, the following errors throws:
File "E:\pythonroot\myproject\..\myproject\myapp\models.py", line 19
SyntaxError: Non-ASCII character '\xe4' in file
E:\pythonroot\myproject\..\myproject\myapp\models.py on line 19, but no encoding declare开发者_开发技巧d; see http://www.python.org/peps/pep-0263.html for details
It seems that manage.py cannot process non-ascii character in my verbose_name. Anything i have done wrong?
Thank you.
You have to specify an encoding. Add the following line as the first line of your models.py
file.
# encoding: utf-8
Update
The OP has edited his question to say that the "models.py
is encoded in Unicode". Then the error is strange. It works for me using Django 1.2.1, Python 2.6.2 on Ubuntu Jaunty.
Update 2
Can you post the encoding string you have used for your models.py
?
精彩评论