Как отобразить несколько страниц с помощью одной функции представления // Python

В настоящее время у меня есть приложение, которое отображает .HTML pdf документы в зависимости от того, выбрано ли значение bool или нет.

Проблема в том, что приложение не может отобразить обе страницы, если выбрано более 1 значения Bool, мой текущий код выглядит следующим образом :

import tempfile
def printReports(request , reports_pk):
    pkForm = get_object_or_404(SettingsClass , pk=reports_pk)

    complexName = pkForm.Complex
    if pkForm.Trial_balance_Monthly == True:
        ### Printing Trial Balance PDF
        response = HttpResponse(content_type= 'application/pdf')
        response['Content-Disposition']= 'attachment; filename=TrialBalance' + \
            str(datetime.now()) + '.pdf'
        response['Content-Transfer-Encoding'] = 'binary'

        html_string=render_to_string('main/reports/trialBalanceYear.html' , content)
        html=HTML(string=html_string)

        result=html.write_pdf()

        with tempfile.NamedTemporaryFile(delete=True) as output:
            output.write(result)
            output.flush()

            output.seek(0)
            response.write(output.read())

            return response

    if pkForm.Trial_balance_Monthly == True:
       
        ### Printing Trial Balance PDF
        response = HttpResponse(content_type= 'application/pdf')
        response['Content-Disposition']= 'attachment; filename=TrialBalanceMonthly' + \
            str(datetime.now()) + '.pdf'
        response['Content-Transfer-Encoding'] = 'binary'

        html_string=render_to_string('main/reports/trialBalanceMonthly.html' , content)
        html=HTML(string=html_string)

        result=html.write_pdf()

        with tempfile.NamedTemporaryFile(delete=True) as output:
            output.write(result)
            output.flush()

            output.seek(0)
            response.write(output.read())

Есть ли способ заставить приложение отображать более 1 страницы? (Я не думаю, что редирект будет работать для этого)

Вернуться на верх