how to send file in django response

from django.http import HttpResponse
from django.core.files import File
import os

def download_file(request):
    # Replace 'path/to/your/file.txt' with the actual path to your file
    file_path = 'path/to/your/file.txt'

    # Open the file using Django's File class
    with open(file_path, 'rb') as file:
        response = HttpResponse(File(file), content_type='application/octet-stream')

        # Set the Content-Disposition header to prompt the user to download the file
        response['Content-Disposition'] = 'attachment; filename={}'.format(os.path.basename(file_path))

        return response

Make sure to replace 'path/to/your/file.txt' with the actual path to your file. This view function, when called, will send the specified file as a downloadable response.