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

CSVStreamingRenderer Example #68

Open
ghost opened this issue Oct 11, 2017 · 2 comments
Open

CSVStreamingRenderer Example #68

ghost opened this issue Oct 11, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 11, 2017

Hey there, I am trying to implement a streaming CSV renderer within a list API view and am having trouble with the code provided in renderers.py. Is it possible to get a full example in example/views.py that shows its usage?

@jrzerr
Copy link
Contributor

jrzerr commented Nov 2, 2017

Here is how I use it:

class CSVStreamingView(APIView):
    renderer_classes = [CSVStreamingRenderer]
    def get(self, request, format=None):
        if format == "csv":
            request.accepted_renderer.header = [
                'keya',
                'keyb'
            ]
            data = [ {'keya': 3, 'keyb': 4}, {'keya': 6, 'keyb': 7} ]
            response = StreamingHttpResponse(
                request.accepted_renderer.render(data),
                content_type="text/csv")
            return response        

@ghost
Copy link
Author

ghost commented Nov 2, 2017

Awesome, thank you. It turned out that it was more an issue with the queryset not being paged rather than django CSV renderer. I'll pop my solution here.

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

1 participant