开发者社区> 问答> 正文

ordinal not in range(128):报错

Exception Value: 'ascii' codec can't encode characters in position 55-56: ordinal not in range(128):报错

如果在models.py 里这样定义:

models.py:
infopic = models.FileField(upload_to='./pic/%Y/%m/%d/%H/', blank=True, null=True)

fomrs.py:
infopic = forms.FileField(label=u'相关图片', required=False)


vimews.py:
 if form.is_valid():
            newinfo = Gqinfo(
                title = form.cleaned_data['title'],
                content = form.cleaned_data['content'],
                infopic = form.cleaned_data['infopic'],
                user = request.user,
                        )
            newinfo.save()

 

如果上传的图片里路径或图片的名字是中文的。比如: 中国.jpg 中国123.jpb

在发布信息的时候就会出错。提示:

 

 

Environment:


Request Method: POST
Request URL: http://www.aaa.com/post

Exception Type: UnicodeEncodeError at /post/
Exception Value: 'ascii' codec can't encode characters in position 55-56: ordinal not in range(128)

 

 

UnicodeEncodeError at /post/
'ascii' codec can't encode characters in position 55-56: ordinal not in range(128)Request Method: POST
Request URL: http://www.gq.com/post/
Django Version: 1.5.2
Exception Type: UnicodeEncodeError
Exception Value: 'ascii' codec can't encode characters in position 55-56: ordinal not in range(128)
Exception Location: /usr/lib/python2.6/genericpath.py in exists, line 18
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path: ['/usr/lib/python26.zip',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/lib/python2.6/site-packages',

 

 

 

难道是那图片的路径不能是中文的吗?

 

展开
收起
kun坤 2020-06-14 09:51:34 1436 0
1 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载