# -*- coding: utf-8 -*- from django.http import HttpResponse def xls_to_response(content, filename=None, filename_encode='windows-1251'): """Выводит content в django.http.HttpResponse, который и возвращает.""" response = HttpResponse(content, mimetype='application/ms-excel') if filename: if filename_encode: filename = filename.encode(filename_encode) response['Content-Disposition'] = ('attachment; filename="%s"' % filename.replace('"', "''")) return response