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 ...
随机推荐
- SharePoint自动化系列——Manage "Site Subscriptions" using PowerShell
转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 你可以将普通的sites加入到你的site subscriptions中,前提是你需要有一个 Te ...
- ci 基础知识
//建立虚拟主机 2.下载完毕后,解压,并将其复制粘贴到程序的主目录(d:/wamp/xmall/),然后再将其重命名为"myshop",那么"myshop" ...
- HDU 4810 Wall Painting
Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- android 引入phonegap
步骤: 1.复制cordova-2.9.0.jar 到lib文件下 2.在assets文件下创建www文件夹及其cordova.js .jquery.js.jquery.mobile-1.3.2.cs ...
- Python3基础 大于一个数的同时小于一个数
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- Java程序员必备的6款最佳开发工具
工欲善其事,必先利其器.每一个Java程序员都有其惯用的工具组件.对于Java程序员,各种有用的软件和工具泛滥成灾.初级开发人员要么找不到合适的工具,要么在寻找过程中浪费了大量的时间.下面,我将为大家 ...
- .Net文件*夹*操作
一.文件夹操作 Directory类,DirectoryInfo类.使用using System.IO命名空间 (一)创建文件夹 方法一: private string path = @"F ...
- :判断101-200之间有多少个素数,并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反之是素数。
package C; public class Sushu { public static void main(String[] args) { int sum=0; for (int i = 101 ...
- SSMS Tools Pack
http://www.ssmstoolspack.com/Features Format SQL 大小写切换,只切换关键字 http://www.ssmstoolspack.com/Features? ...
- 并行parallel和并发concurrent的区别
http://stackoverflow.com/questions/1050222/concurrency-vs-parallelism-what-is-the-difference Concurr ...