[Answer]-Django admin single action to return 2 csv files

1👍

A single http request can trigger only a single response. You should zip the two files, and download them zipped result.

You can easily create a zip file using Python’s zipfile library.

Even when you’ve the zipfile ready, you might want to return something else than the file as is. For the browser to provide you its download view, you need some special headers set on you HttpResponse instance. Example follows:

    response = HttpResponse(json_data, content_type='application/json')
    response['Content-Disposition'] = 'attachment; filename="download.json"' % self.get_filename()
    return response

This will trigger the download window in the browser.

To get these working under the admin, is not obvious, see the Django docs.

👤Akasha

Leave a comment