背景
最近在学习django,今天在启动django admin的时候,发现admin 默认的css没有加载到,然后一直报这个错误,然后去Google。
开始以为是css路径的问题,就各种改settings下的路径设置,发现怎么改也不对,后来经过一上午的搜索,发现这是Python 2.x 的bug。
抛异常的具体信息如下:
File "D:\Program Files\Python 2.7\lib\mimetypes.py", line 249, in enum_types
ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xbc in position 0: ordinal not in range(128)
解决办法:
根据提示打开 \Python 2.x\lib\mimetypes.py
def enum_types(mimedb):
i = 0
while True:
try:
ctype = _winreg.EnumKey(mimedb, i)
except EnvironmentError:
break
#try:
#ctype = ctype.encode(default_encoding) # omit in 3.x!
#except UnicodeEncodeError:
#pass
else:
yield ctype
i += 1
如上,注释或者去掉其中的
try:
ctype = ctype.encode(default_encoding) # omit in 3.x!
except UnicodeEncodeError:
pass
然后重新运行django admin即可
Python 官方bug描述 http://bugs.python.org/issue10490