Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

response['Content-Type'] not set #76

Open
int-ua opened this issue Aug 20, 2018 · 1 comment
Open

response['Content-Type'] not set #76

int-ua opened this issue Aug 20, 2018 · 1 comment

Comments

@int-ua
Copy link

int-ua commented Aug 20, 2018

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.

@ManPython
Copy link

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants