Django pdf файл не завершает загрузку в браузере

views.py

def showName(request):
if request.method == 'POST':
    uploaded_file = request.FILES['user_initial_pdf']
    if uploaded_file is not None:
        import PyPDF2
        import os
        from io import BytesIO
        from django.conf import settings
        #Merging 2 pdf files
        pdfObject1 = PyPDF2.PdfFileReader(uploaded_file)
        pdfWriter1 = PyPDF2.PdfFileWriter()
        for pageNum in range(pdfObject1.numPages):
            pageObj = pdfObject1.getPage(pageNum)
            pdfWriter1.addPage(pageObj)
        for pageNum in range(pdfObject1.numPages):
            pageObj = pdfObject1.getPage(pageNum)
            pdfWriter1.addPage(pageObj)
        pdfOutputFile = BytesIO()
        pdfWriter1.write(pdfOutputFile)
        #using FileSystem storage to store the merged pdf in merdia directory
        fs = FileSystemStorage()
        fs.save(uploaded_file.name,pdfOutputFile)
        #getting the file path
        file_path = settings.MEDIA_ROOT +'/'+ uploaded_file.name
        #creating wrapper of file object of the required pdf to be sent as downloadable file to client side
        wrapper = FileWrapper(open(file_path,"r",encoding="utf8"))
        response = HttpResponse(wrapper, content_type = 'application/pdf')
        response['Content-Length'] = os.path.getsize( file_path )
        response['Content-Disposition'] = 'attachment; filename="sample.pdf"'
        return response
    else:
        return HttpResponse("File has not been uploaded or is empty!")
return HttpResponse("No Post method")

Выше приведена функция в файле views.py, которая принимает один pdf, объединяет его с самим собой и отправляет обратно пользователю.

Ошибка/проблема: По какой-то причине мой pdf-файл застревает на этапе, близком к завершению, и никогда не завершается PDF File Not Finishing downloading

Примечание: Я только начал изучать django и не использую никаких моделей, так как я еще не начал, поэтому, пожалуйста, простите меня за то, что я написал функциональность и получил файл в самой функции.

Консоль:

[16/Jan/2022 12:10:35] "POST /showName HTTP/1.1" 200 2977
[16/Jan/2022 12:10:39] "GET /showName HTTP/1.1" 200 14
Вернуться на верх