def get_content_type(mimetype,字符集):
"""返回具有 mimetype 字符集的完整内容类型字符串。
如果 mimetype 表示文本,则字符集将作为字符集附加
参数,否则返回 mimetype 不变。
:param mimetype:用作内容类型的 mimetype。
:param charset: 要附加的字符集,以防它是文本 mimetype。
:return: 内容类型。
"""
如果 mimetype.startswith('text/') 或 \
mimetype == '应用程序/xml' 或 \
(mimetype.startswith('application/') 和
mimetype.endswith('+xml')):
模仿类型 += '; 字符集=' + 字符集
返回 mimetype
我刚开始接触这个,有一个编码问题。
为什么不判断“mimetype == 'application/json'”?
JSON 始终为 UTF-8。
感谢您的帮助。
最有用的评论
JSON 始终为 UTF-8。