0

I'm doing a dynamic Django template that fills a table with information and I'm currently running issues with data overflow from one page to another which distorts the layout for the header and footer elements

`

        def create_render(data_header, data_body, data_footer=None):
            """
            Función para crear el renderizado de las pantallas de header y body
            Se neceista pasarle un diccionario con el header y uno con los del boddy y el base_url
            """

            def get_page_body(boxes):
                for box in boxes:
                    if box.element_tag == "body":
                        return box
                    return get_page_body(box.all_children())

            URL_BASE=request.build_absolute_uri()
            html_string = render_to_string(data_header["template"], data_header)
            html = HTML(string=html_string, base_url=URL_BASE)
            header = html.render()
            footer = None
            if data_footer is not None:
                html_string = render_to_string(data_footer["template"], data_footer)
                html = HTML(string=html_string, base_url=URL_BASE)
                footer = html.render()
            # Main template
            html_string = render_to_string(data_body["template"], data_body)
            html = HTML(string=html_string, base_url=URL_BASE)
            main_doc = html.render()
            exists_links = False
            header_page = header.pages[0]
            exists_links = exists_links or header_page.links
            header_body = get_page_body(header_page._page_box.all_children())
            header_body = header_body.copy_with_children(header_body.all_children())
            exists_links_footer = False
            footer_body = None
            footer_page = None
            if footer is not None:
                footer_page = footer.pages[0]
                exists_links_footer = exists_links_footer or footer_page.links
                footer_body = get_page_body(footer_page._page_box.all_children())
                footer_body = footer_body.copy_with_children(footer_body.all_children())
            # Insert header and footer in main doc
            for i, page in enumerate(main_doc.pages):
                page_body = get_page_body(page._page_box.all_children())
                page_body.children += header_body.all_children()
                if exists_links:
                    page.links.extend(header_page.links)
                if footer_body is not None:
                    page_body.children += footer_body.all_children()
                if exists_links_footer:
                    page.links.extend(footer_page.links)
            return main_doc

`

enter image description here

I've changed the CSS tags, such as word-break and word-wrap and height. I've also tried transforming the page. I've added the weasyprint function if it helps. I'm joining the elements and rendering all to one single html.

0 Answers0