def send_file(request):
    newfile = NamedTemporaryFile(suffix='.txt')
wrapper = FileWrapper(newfile)
response = HttpResponse(wrapper, content_type=mime_type)
response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(
    modelfile.name)
response['Content-Length'] = os.path.getsize(modelfile.name)
return response
Removing tmp file after return HttpResponse in django