djangodjango-adminhtml-escape-characters

Django Admin format_html_join cannot seperate with new line <br>


format_html_join(
        '<br>', '<br><a href="{}">{}</a>', (
            (reverse("admin:research_webproductpage_change", args=[wpp.id]), wpp.title[:30]) for wpp in webproductpages
            )
        )

Above I am trying to add many to many links to my django admin list display which I did succesfully. But <br> or "\n" not working as seperators, although <br> is working in the second parameter. If I put <br> in the first parameter it appears in double quote not as an html. Or If I put "\n" it does not appear at all.
I want to put links row by row because o it looks better then. What is wrong with my code?


Solution

  • You can mark your separator safe !

    from django.utils.safestring import mark_safe
    
    format_html_join(
        mark_safe('<br>'),
        '<a href="{}">{}</a>',
        ...
    )