django管理后台保存中文信息报错,但是信息已经保存到数据库中,并且在前台可以读取到。看来错误应该发生在保存后的view页面编码问题,但找不到具体如何解决的方法。详细错误提示如下:
[quote]UnicodeEncodeError at /admin/contents/thread/add/
'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Request Method: POST
Request URL: http://localhost/admin/contents/thread/add/
Exception Type: UnicodeEncodeError
Exception Value: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Exception Location: J:\Python25\Lib\site-packages\django\utils\encoding.py in force_unicode, line 53
Python Executable: J:\Python25\python.exe
Python Version: 2.5.2
Python Path: ['J:\\python\\workspace\\weixi', 'J:\\Python25\\python25.zip', 'J:\\Python25\\DLLs', 'J:\\Python25\\lib', 'J:\\Python25\\lib\\plat-win', 'J:\\Python25\\lib\\lib-tk', 'J:\\Python25', 'J:\\Python25\\lib\\site-packages', 'J:\\Python25\\lib\\site-packages\\PIL', 'J:\\python\\django']
Server time: Wed, 9 七月 2008 16:35:48 +0800
[/quote]
错误原因:
把对象里面的 def __str__(self): 换成 def __unicode__(self): 就好了,太神奇了。
参考:
[url]http://blog.csdn.net/jiangnanandi/archive/2008/12/21/3574007.aspx[/url]
[url]http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist[/url]
[quote]UnicodeEncodeError at /admin/contents/thread/add/
'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Request Method: POST
Request URL: http://localhost/admin/contents/thread/add/
Exception Type: UnicodeEncodeError
Exception Value: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Exception Location: J:\Python25\Lib\site-packages\django\utils\encoding.py in force_unicode, line 53
Python Executable: J:\Python25\python.exe
Python Version: 2.5.2
Python Path: ['J:\\python\\workspace\\weixi', 'J:\\Python25\\python25.zip', 'J:\\Python25\\DLLs', 'J:\\Python25\\lib', 'J:\\Python25\\lib\\plat-win', 'J:\\Python25\\lib\\lib-tk', 'J:\\Python25', 'J:\\Python25\\lib\\site-packages', 'J:\\Python25\\lib\\site-packages\\PIL', 'J:\\python\\django']
Server time: Wed, 9 七月 2008 16:35:48 +0800
[/quote]
错误原因:
把对象里面的 def __str__(self): 换成 def __unicode__(self): 就好了,太神奇了。
参考:
[url]http://blog.csdn.net/jiangnanandi/archive/2008/12/21/3574007.aspx[/url]
[url]http://code.djangoproject.com/wiki/UnicodeBranch#PortingApplicationsTheQuickChecklist[/url]