在下面我的片段,我在处理文本,多数民众赞成的字符串:Déclaration.pngPython的编码 - 错误:“Latin-1的”编解码器不能编码字符
我返回描述为Unicode:
return self.render_json(request, {..."description": u''.join((instance.description)),..})
在另一功能中,我使用以上如下的描述:
if document.description:
file_name = document.description.split(".")
file_name = "{}.{}.{}".format(
"_".join(file_name[:-1]),
str(document.id),
file_name[-1]
)
file_name是:[u'De\u0301claration', u'png']
当我尝试FILE_NAME我收到以下错误.format():
error: 'latin-1' codec can't encode character u'\u0301' in position 2: ordinal not in range(256)
任何想法?
你想要什么输出看起来像 – Navidad20
我想是“德\ u0301claration.123456 .png' – Brandon