[Answered ]-How to format template with django?

1👍

The tabulate package requires a third parameter tablefmt in order to output HTML, so you need to pass tablefmt="html" to the tabulate() function after headers.

    return tabulate(
        zip_longest(*matches),  # type: ignore
        headers=[
            "aantal fruit",
            "naam fruit",
            "kosten fruit",
        ],
        tablefmt="html",
    )

You will need to wrap this output with mark_safe() from django.utils.safestring.

Note that this produces an entire HTML table with all tags, so instead of looping over the table rows you can simply output content by itself:

<div class="wishlist">
    {{ content }}
</div>

At this point it’s worth renaming content to something more appropriate like table.

Leave a comment