D
D
dimas75252019-01-15 17:10:19
Django
dimas7525, 2019-01-15 17:10:19

How to give a Csv file while changing the name?

There is a file, let's say itog.csv in the upload folder. How to give the file to the user while changing the name to itof_final.csv?
You need to give in views

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick V, 2019-01-15
@dimas7525

Something like this
def get(self, request, *args, **kwargs):
        dataset = self.resource_class.export(queryset=self.get_queryset()) # тут поменяй логику получения csv файла на свою
        response = StreamingHttpResponse(dataset, content_type='text/csv')
        response['Content-Disposition'] = 'attachment; filename="export.csv"' # export.csv меняй на то имя какое тебе необходимо
        return response

A
Alexander, 2019-01-15
@NeiroNx

Content-Disposition header

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question