标签:xadmin %s text att attr span request file res
在使用xadmin过程中,导出xls文件文件名为乱码问题解决:
这时候去修改xadmin->plugins->export.py中:
def get_response(self, response, context, *args, **kwargs): file_type = self.request.GET.get(‘export_type‘, ‘csv‘) response = HttpResponse( content_type="%s; charset=gbk" % self.export_mimes[file_type]) file_name = self.opts.verbose_name.replace(‘ ‘, ‘_‘) # response[‘Content-Disposition‘] = (‘attachment; filename=%s.%s‘ % ( # file_name, file_type)).encode(‘utf-8‘) response[‘Content-Disposition‘] = (‘attachment; filename=%s.%s‘ % ( file_name, file_type)) response.write(getattr(self, ‘get_%s_export‘ % file_type)(context)) return response
把
response[‘Content-Disposition‘] = (‘attachment; filename=%s.%s‘ % ( file_name, file_type)).encode(‘utf-8‘)
修改为:
response[‘Content-Disposition‘] = (‘attachment; filename=%s.%s‘ % ( file_name, file_type))
即,去掉“.encode(‘utf-8‘)”即可;
标签:xadmin %s text att attr span request file res
原文地址:https://www.cnblogs.com/jingzaixin/p/11491399.html