2👍
✅
This is already documented in docs – https://docs.djangoproject.com/en/dev/ref/request-response/#telling-the-browser-to-treat-the-response-as-a-file-attachment
response = HttpResponse(my_data, content_type='text/x-python')
response['Content-Disposition'] = 'attachment; filename="foo.py"'
Source:stackexchange.com