Django 上传文件(bootstrap file input插件) 中文乱码 解决 (python3)
2017-11-08 12:19
1806 查看
上传文件示例:
python3代码:
python3代码:
f = request.FILES.get('playerList', None) # 获取 上传文件,如果没有,默认为 None ''' 写入文件 bytes方式 ''' fileName = 'levelRewards_' + str( int( time.time()*1000 - 8*60*60*1000 ) ) + '.txt' # UTC时间戳,ms,int取整 path = 'slg/uploads/' + fileName with open(path, 'w') as destination: # 写方式 for chunk in f.chunks(): destination.write( chunk.decode() ) # python3 中,直接 将 bytes 转换为 utf-8 就行,直接 decode(),没有encode了!!!!!!! destination.close() ''' 读取文件 ''' playerList = [] # 形如: [ [10000121321, 1000230, 20], [10002133222, 1000222, 10;] ] with open(path, 'r', encoding='utf-8') as f: # 只读方式 for line in f: line = line.strip() # 去掉 换行符 \n line = line.replace(";", "") # 去掉 最后一位的 “ ; ”号 playerList.append( line.split(', ') ) # print(playerList) f.close()
相关文章推荐
- bootstrap3 文件上传插件fileinput中文说明文档
- Bootstrap文件上传插件File Input的使用
- php 应用 bootstrap-fileinput 上传文件 插件 操作的方法
- Bootstrap文件上传插件File Input的使用
- 支持多文件上传,预览,拖拽,基于bootstrap的上传插件fileinput 的ajax异步上传(转载)
- 解决HttpClient的FilePart上传文件中使用中文名称文件名乱码问题
- 解决python中用zipfile解压缩文件时中文文件名乱码的问题
- Bootstrap -- 文件上传插件File Input的使用
- 支持多文件上传,预览,拖拽,基于bootstrap的上传插件fileinput的ajax异步上传
- Bootstrap FileInput多文件上传插件使用详解(包括Java代码)
- 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
- 基于BootStrap Metronic开发框架经验小结【五】Bootstrap File Input文件上传插件的用法详解
- php 应用 bootstrap-fileinput 上传文件 插件 操作的方法
- Bootstrap的fileinput插件实现多文件上传的方法
- bootstrap 文件上传插件 fileinput.min.js 可以预览图片
- 基于BootStrap Metronic开发框架经验小结【五】Bootstrap File Input文件上传插件的用法详解
- 解决HttpClient的FilePart上传文件中使用中文名称文件名乱码问题
- 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用
- Bootstrap的fileinput插件实现多文件上传的方法
- 基于Metronic的Bootstrap开发框架经验总结(5)--Bootstrap文件上传插件File Input的使用