2015-05-30 20 views
0

IM尝试上传文件,但是当文件名具有像“ó”这样的字符时,'ascii'编码解码器不能在位置59处编码字符u'\ xf3':序号不在范围内(128) 即时尝试obj.file = smart_unicode(form.cleaned_data["file"])之前保存()在views.pyDjango:如何在save()上没有UnicodeEncodeError的情况下上载文件?

def file(instance, filename): 
    i = datetime.now() 
    filename = smart_unicode(filename) 

    return "archivos/files/%s_%s" % (str("a")+i.strftime('%Y-%m-%d'), filename) 
上models.py

,但使用view.py时不要有错误和保存模型的名称为文件正确的,但不要有文件,当没有使用smart_unicode时出现错误,用特殊的caracter字体有上传问题。

回答

相关问题