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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 解决python3 UnicodeEncodeError: 'gbk' codec can't encode character '\xXX' in position XX

    从网上抓了一些字节流,想打印出来结果发生了一下错误: UnicodeEncodeError: 'gbk' codec can't encode character '\xbb' in position ...

  4. 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 ...

  5. web.py+mysql插入中文提示query = query.encode(charset) UnicodeEncodeError: 'latin-1' codec can't encode characters in position 86-100

    对于中文编码的问题,总会出现各种各样恶心的错误,还不知道应该怎么解决,首先,你从最开头就应该关注编码问题,尽量保证所有的编码方式都是一致的 用python+web.py+mysql来写程序,首先要保证 ...

  6. python 安装pip的时候出现UnicodeEncodeError错误

    另外 Python 中一个比较常见的问题是编码问题,若遇到类似"UnicodeEncodeError: 'ascii' codec can't encode character u'\u62 ...

  7. python:UnicodeEncodeError

    problem: (<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u'[taobao_cocobe ...

  8. Python的Ftplib问题:UnicodeEncodeError: 'latin-1' codec can't encode characters的解决方法

    ftplib中有一个方法是cwd,用来切换目录,需要传入一个dirname,经过个人测试,该dirname不能含有汉字,会抛出:UnicodeEncodeError: 'latin-1' codec ...

  9. 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 ...

随机推荐

  1. 数据库 使用DML语句更改数据

    使用DML语句更改数据 添加新数据: 插入单行语句: Insert into 表名(列名)values(‘值’); 插入多行:insert into 表名(列名,…..) Values(‘值’,’值’ ...

  2. 浅谈Apache性能调优

    做了很多WEB系统性能测试,都知道了解测试环境,服务器硬件配置,web服务器参数配置是我们开始测试前首先要做的事情. 针对并发数量来说,不同数量级的用户并发,需求的服务器和web服务参数肯定是不同的. ...

  3. XMLHttpRequest 2.0与FileReader接口的方法

    jsonpd的实现: var jsonp = function (options) { var url = options.url, params = options.params || {}, ca ...

  4. Easyui部分组件讲解

    Easyui部分组件讲解 目  录 1.... Accordion(可折叠标签)... 2 1.1          实例... 2 1.2          参数... 3 2.... DateBo ...

  5. JLINK使用教程详解,以及与JTAG区别

    对于一个新手来说,一切都不容易. 而从头学起也是一件非常美好的事. 观看     调试ARM,要遵循ARM的调试接口协议,JTAG就是其中的一种.当仿真时,IAR.KEIL.ADS等都有一个公共的调试 ...

  6. sysbench 0.5 oltp测试笔记

    sysbench 0.5相比0.4版本的主要变化是,oltp测试结合了lua脚本,不需要修改源码,通过自定义lua脚本就可以实现不同业务类型的测试.同时0.5相比0.4需要消耗更多的cpu资源. 1. ...

  7. SqlSever基础 datepart 获取一个日期的年份

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  8. 在Quartus II中分配管脚的两种常用方法

    在Quartus II中分配管脚的两种常用方法 示范程序 seg7_test.v 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 /* * ...

  9. Java-集合框架整理

    一.List 接口集合: 1.优势以及特点:有序,允许重复元素 . 2.实现类: * AarrayList 类:不同步,可变长度数组,倍增率为 1/n ; * LinkedList 类:不同步,链表结 ...

  10. jQuery对html进行Encode和Decode

    最近需要在前台对编辑器生成的html代码做处理,需要进行编码,考虑到js没有直接对html编码的支持,看了下jQuery的实现,发现真是超级简单呀,顺便记录一下,需要的时候可以参考一下. functi ...