繁体   English   中英

如何保存名称为 utf-8 的文件

[英]how can save file with names in utf-8

我需要使用 utf-8 名称保存文件。但是当我这样做时 django 错误:

UnicodeEncodeError at /uploaded/document/ 'فیلتر.png'
'ascii' codec can't encode characters in position 55-59: ordinal not in range(128)

虽然,我的文件字段喜欢它:

# -*- coding: utf-8 -*-
def get_path(instance, filename):
    return u' '.join((u'document', filename)).encode('utf-8').strip()

class Document(models.Model):
    file_path = models.FileField(verbose_name='File', upload_to=get_path,
                                 storage=FileSystemStorage(base_url=settings.LOCAL_MEDIA_URL))

我该如何解决? 我使用tastepie api 上传文件。

我的问题在这里回答: https://itekblog.com/ascii-codec-cant-encode-characters-in-position/#The_Code

我应该更改 apache2 编码:/etc/apache/envvars

导出 LANG='en_US.UTF-8' 导出 LC_ALL='en_US.UTF-8'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM