提交后出现如下错误
UnicodeEncodeError at /admin/polls/question/add/
'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
Request Method: POST
Request URL: http://192.168.1.50:8000/admin/polls/question/add/
Django Version: 1.9.6
Exception Type: UnicodeEncodeError
Exception Value:
'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)
Exception Location: /usr/local/lib/python2.7/dist-packages/django/utils/encoding.py in force_text, line 80
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/saplingcode/site/mysite',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: 星期六, 21 五月 2016 16:10:48 +0800
解决办法:在admin.y添加下面三行代码即可
import sys;
reload(sys);
sys.setdefaultencoding("utf8")