django下载导出文件时,中文名解决(Content-Disposition中文)

clientSystem = request.META['HTTP_USER_AGENT']

如果是windows则按cp936编码,否则按utf-8编码
        if clientSystem.find('Windows') > -1:
            filename = filename.encode('cp936')
        else:
            filename = filename.encode('utf-8')
        
        response['Content-Disposition'] = 'attachment;filename=%s.xls' % filename

你可能感兴趣的:(django下载导出文件时,中文名解决(Content-Disposition中文))