def create_csv_response(filename, header, datarows):
 response = HttpResponse(content_type='text/csv')
 response['Content-Disposition'] = 'attachment; filename={0}'.format(filename)
 csvwriter = csv.writer(response, dialect='excel', quotechar='"', quoting=csv.QUOTE_ALL)
 encoded_header = [unicode(s).encode('utf-8') for s in header]
 csvwriter.writerow(encoded_header)
 for datarow in datarows:
  encoded_row = [unicode(s).encode('utf-8') for s in datarow]
  csvwriter.writerow(encoded_row)
 return response

def create_csv_response ( filename , header , datarows ) : response = HttpResponse ( content_type = 'text/csv' ) response [ 'Content-Disposition' ] = 'attachment; filename={0}' . format ( filename ) csvwriter = csv . writer ( response , dialect = 'excel' , quotechar = '"' , quoting = csv . QUOTE_ALL ) encoded_header = [ unicode ( s ) . encode ( 'utf-8' ) for s in header ] csvwriter . writerow ( encoded_header ) for datarow in datarows : encoded_row = [ unicode ( s ) . encode ( 'utf-8' ) for s in datarow ] csvwriter . writerow ( encoded_row ) return response
create an httpresponse with an attached .