UnicodeEncodeError
UnicodeEncodeError at /admin/shop/product/add/
'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/shop/product/add/
Django Version: 1.9.4
Exception Type: UnicodeEncodeError
Exception Value:
'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Exception Location: /Library/Python/2.7/site-packages/django/utils/encoding.py in force_text, line 80
Python Executable: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
Python Path:
['/Users/similarface/PycharmProjects/mybook',
'/Library/Python/2.7/site-packages/beautifulsoup4-4.4.0-py2.7.egg',
'/Library/Python/2.7/site-packages/html5lib-1.0b7-py2.7.egg',
'/Library/Python/2.7/site-packages/requests-2.7.0-py2.7.egg',
'/Library/Python/2.7/site-packages/Scrapy-1.0.3-py2.7.egg',
'/Library/Python/2.7/site-packages/service_identity-14.0.0-py2.7.egg',
'/Library/Python/2.7/site-packages/six-1.9.0-py2.7.egg',
'/Library/Python/2.7/site-packages/cssselect-0.9.1-py2.7.egg',
'/Library/Python/2.7/site-packages/lxml-3.4.4-py2.7-macosx-10.10-intel.egg',
'/Library/Python/2.7/site-packages/queuelib-1.3.0-py2.7.egg',
'/Library/Python/2.7/site-packages/w3lib-1.12.0-py2.7.egg',
'/Library/Python/2.7/site-packages/pyasn1_modules-0.0.7-py2.7.egg',
'/Library/Python/2.7/site-packages/pyasn1-0.1.8-py2.7.egg',
'/Library/Python/2.7/site-packages/characteristic-14.3.0-py2.7.egg',
'/Library/Python/2.7/site-packages/image-1.4.1-py2.7.egg',
'/Library/Python/2.7/site-packages/Pillow-2.9.0-py2.7-macosx-10.10-intel.egg',
'/Library/Python/2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.10-intel.egg',
'/Library/Python/2.7/site-packages/nose-1.3.7-py2.7.egg',
'/Library/Python/2.7/site-packages/tornado-4.3-py2.7-macosx-10.10-intel.egg',
'/Users/similarface/PycharmProjects/mybook',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
解决办法:
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Product(models.Model):
category=models.ForeignKey(Category,related_name='products',verbose_name='分类')
name=models.CharField(max_length=200,db_index=True,verbose_name='名称')
slug=models.SlugField(max_length=200,db_index=True,verbose_name='简称')
@python_2_unicode_compatible
UnicodeEncodeError的更多相关文章
- Python编码问题:UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(12
今天安装了PyScripter编辑器,刚要写代码,突然就出现异常: <span style="font-size:14px;color:#ff0000;">>&g ...
- python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...
- 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX
从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...
- Python读取中文txt文件错误:UnicodeEncodeError: 'gbk' codec can't encode character
with open(file,'r') as f: line=f.readline() i=1 while line: line=line.decode('utf-8') line=f.readlin ...
- web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100
对于中文编码的问题,总会出现各种各样恶心的错误,还不知道应该怎么解决,首先,你从最开头就应该关注编码问题,尽量保证所有的编码方式都是一致的 用python+web.py+mysql来写程序,首先要保证 ...
- python 安装pip的时候出现UnicodeEncodeError错误
另外 Python 中一个比较常见的问题是编码问题,若遇到类似"UnicodeEncodeError: 'ascii' codec can't encode character u'\u62 ...
- python:UnicodeEncodeError
problem: (<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u'[taobao_cocobe ...
- Python的Ftplib问题:UnicodeEncodeError: 'latin-1' codec can't encode characters的解决方法
ftplib中有一个方法是cwd,用来切换目录,需要传入一个dirname,经过个人测试,该dirname不能含有汉字,会抛出:UnicodeEncodeError: 'latin-1' codec ...
- UnicodeEncodeError: 'latin-1' codec can't encode character 解决sae flask 中文问题
#encoding=utf-8 #中文编码支持 import MySQLdb from flask import Flask, g, request app = Flask(__name__) app ...
随机推荐
- ubuntu下查看cpu信息
查看CPU信息cat /proc/cpuinfo 几个cpu more /proc/cpuinfo |grep "physical id"|uniq|wc -l 每个cpu是几核( ...
- apache-common pool的使用
Apache commons-pool本质上是"对象池",即通过一定的规则来维护对象集合的容器;commos-pool在很多场景中,用来实现"连接池"/&quo ...
- A fatal error has been detected by the Java Runtime Environment(jdk 1.6的一个BUG)
几天做项目,生成一堆注解的实体,当实体数超过86个时,jvm报错: # # A fatal error has been detected by the Java Runtime Environmen ...
- MySQL中删除重复数据的简单方法,mysql删除重复数据
MYSQL里有五百万数据,但大多是重复的,真实的就180万,于是想怎样把这些重复的数据搞出来,在网上找了一圈,好多是用NOT IN这样的代码,这样效率很低,自己琢磨组合了一下,找到一个高效的处理方式, ...
- xcode下编译.a文件的路径
http://www.it165.net/pro/html/201503/36842.html 每当我们编译之后, 实际上系统就给我编译好了一个可以运行的.app文件,在某个路径下 如果我们建立的是静 ...
- Win32工程中使用MFCdll的解决方法
我的项目是Win32,先使用了 Standard Windows Libraries,可后期又要要使用MFC的dll,所以要更改工程属性 ,MFC 的dll可以使用了,但标准的windows的dll出 ...
- XMPP Server
XMPPFramework,编译失败,@import libxmlSimu后提示:Module 'libxmlSimu' not found XMPP协议实现原理介绍 XMPP协议学习笔记 四.地址格 ...
- Exchange 2010 邮箱大小限制原则
在 Exchange中文站 的QQ群(68280328)里经常会有朋友问到关于 Exchange 2010 邮件大小限制的问题,因为有许多地方,而且定义的内容又是同样的,所以,让本来很简单的限制原则变 ...
- BZOJ 3226: [Sdoi2008]校门外的区间
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3226 题意:初始集合S为空.模拟四种集合操作:集合并.交.差.补集并. 思路:区间 ...
- 【转载】教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神
原文:教你分分钟学会用python爬虫框架Scrapy爬取心目中的女神 本博文将带领你从入门到精通爬虫框架Scrapy,最终具备爬取任何网页的数据的能力.本文以校花网为例进行爬取,校花网:http:/ ...