django-rest-framework-csv icon indicating copy to clipboard operation
django-rest-framework-csv copied to clipboard

response['Content-Type'] not set

Open int-ua opened this issue 7 years ago • 1 comments

Is it an issue with my code or a bug of django-rest-framework-csv?

class DataList(generics.ListAPIView):
    ...
    renderer_classes = [CSVRendererWithUnderscores, ]
    ...
    def finalize_response(self, request, response, *args, **kwargs):
        response = super(DataList, self)\
            .finalize_response(request, response, *args, **kwargs)
        response['Content-Disposition'] = \
            "attachment; filename=data_{:s}.csv"\
            .format(kwargs['year'])
        return response

Adding response['content-type'] = 'text/csv' wouldn't help.

int-ua avatar Aug 20 '18 19:08 int-ua

I agree that exist problem with this and easy set filename to download or add right ['Content-disposition'] I guesing that here was try to set both ['Content-disposition'] and ['content-type'] With this hard is to realize plain/text as txt/csv to show in browser and download as view to set extension as .txt or .csv (instead of autodownload - it's important in case API should provide some tables to usage instaed of json/xml).

ManPython avatar Jul 06 '20 15:07 ManPython