Python Ubuntu服务器上文件上载时出现Ascii代码错误
我的项目在本地主机中正常运行,但项目在服务器中给出ascii码错误Python Ubuntu服务器上文件上载时出现Ascii代码错误,python,django,file,ubuntu,server,Python,Django,File,Ubuntu,Server,我的项目在本地主机中正常运行,但项目在服务器中给出ascii码错误 Django output: 'ascii' codec can't encode character u'\u0130' in position 78: ordinal not in range(128) 这是我的观点 def gallery(request): if admin_permission(request): return HttpResponseRedirect("/")
Django output:
'ascii' codec can't encode character u'\u0130' in position 78: ordinal not in range(128)
这是我的观点
def gallery(request):
if admin_permission(request):
return HttpResponseRedirect("/")
showcase_list = Gallery.objects.all()
if request.method == 'POST':
user = User.objects.get(id=request.user.id)
product_code = request.POST.get('product_code')
photo = request.FILES.get('photo')
small_photo = request.FILES.get('small_photo')
# photo.name = 'photo'
# small_photo.name = 'small_photo'
code = request.POST.get('code')
product = Products.objects.get(product_code=product_code)
gallery = Gallery.objects.create(user=user, code=code, product=product, photo=photo, small_photo=small_photo,
is_active=True)
gallery.save()
return render_to_response('Product/showcase/gallery.html', locals(), context_instance=RequestContext(request))
错误页:
这是文件上载错误。如果文件名包含土耳其语字符,则给出该错误。请。帮帮我…可能的原因是django进程使用C/POSIX语言环境运行:
$ LC_ALL=C python2
>>> import os
>>> os.listdir(u"\u0130")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0130' in position 0: ordinal not in range(128)
$LC\u ALL=C python2
>>>导入操作系统
>>>操作系统列表目录(u“\u0130”)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
UnicodeEncodeError:“ascii”编解码器无法对位置0中的字符u'\u0130'进行编码:序号不在范围内(128)
要解决此问题,请配置utf-8语言环境,例如,
LC\u ALL=C.utf-8
一些代码将非常有用。目前,该问题未提供调试此问题的任何详细信息。完整的回溯和导致异常的代码将非常有用。将回溯作为文本发布(单击“切换到复制粘贴视图”)。相关:是的,我有此错误。我在区域设置中进行了配置,但它不起作用。@KAYKISIZ:“不起作用”的信息量不大。在django服务器内的http请求期间,打印语言
,LC\u ALL
,LC\u CTYPE
,LANG
环境变量。