Python 文件名中的Django Unicode错误
我想指定一个出现在管理站点中的日文人名 所以,我只想这样写:Python 文件名中的Django Unicode错误,python,django,unicode,codec,Python,Django,Unicode,Codec,我想指定一个出现在管理站点中的日文人名 所以,我只想这样写: class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField(u'投稿日時') 但它说: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 57: ordinal not in ra
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField(u'投稿日時')
但它说:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 57:
ordinal not in range(128)
在这种情况下,如何像日语一样使用unicode
完全回溯:
python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/base.py", line 314, in validate
raise CommandError("One or more models did not validate:\n%s" % error_text)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 57: ordinal not in range(128)
python manage.py syncdb
回溯(最近一次呼叫最后一次):
文件“manage.py”,第10行,在
从命令行(sys.argv)执行命令
文件“/Users/me/.virtualenvs/env/lib/python2.7/site packages/django/core/management/_init__.py”,第399行,从命令行执行
utility.execute()
文件“/Users/me/.virtualenvs/env/lib/python2.7/site packages/django/core/management/_init__.py”,执行中第392行
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/Users/me/.virtualenvs/env/lib/python2.7/site-packages/django/core/management/base.py”,第242行,运行时从
self.execute(*args,**选项._dict__;
文件“/Users/me/.virtualenvs/env/lib/python2.7/site packages/django/core/management/base.py”,执行中第284行
self.validate()
文件“/Users/me/.virtualenvs/env/lib/python2.7/site packages/django/core/management/base.py”,第314行,在validate中
raise CommandError(“一个或多个模型未验证:\n%s”%error\u text)
UnicodeDecodeError:“ascii”编解码器无法解码位置57处的字节0xe9:序号不在范围内(128)
好吧,也许可以帮你
将
#-*-编码:utf-8-*-
放在文件顶部,它定义了对utf-8的反编码,这是您需要的请发布完整的traceback@MikeDeSimone不是:我做了,但没用。对不起。我想是我的拼写错误什么的。我也写了coding:utf-8
,但是在复制了你的一个之后,它确实起作用了。原因不是编码
类型。我甚至在外键的列中添加了字段显示名称。