首先感谢
http://code.djangoproject.com/attachment/ticket/7178/encoding.patch...
看了一下是清风发的patch...
Django1.02在MAC下面有一个不大不小的bug.
就是如果有简体中文的内容就会报错....
说没有编码"X-MAC-SIMP-CHINESE"....
这个,首先要怪MacOSX为啥要自己搞一套编码呢???
其次要怪Python怎么不支持Mac的编码呢?
当然,没有办法我们只能hack一下啦.....
找到django目录下面的utils文件夹...打开里面的encoding.py文件....
修改46行左右的一下代码..
关键就是if判断的那一行....
这样就ok了...
def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Similar to smart_unicode, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
"""
if encoding == 'X-MAC-SIMP-CHINESE' : encoding = 'utf-8'
if strings_only and isinstance(s, (types.NoneType, int, long, datetime.datetime, datetime.date, datetime.time, float)):
转载自原文链接, 如需删除请联系管理员。
原文链接:Django在MAC下面的Bug,转载请注明来源!