在下面我的片段,我在處理文本,多數民衆贊成的字符串: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