Как заставить Django выводить URL диспетчера из HTML в столбце Pandas, вместо того, чтобы передавать необработанный HTML?

Я хочу отобразить фрейм данных pandas в HTML, в котором 1 столбец содержит URL-адреса ссылок на другие страницы. Если я пытаюсь отобразить этот HTML, он просто сохраняет сырой HTML, вместо того, чтобы преобразовать URLS:

utils.py

import pandas as pd
df = pd.DataFrame(["2022-007", "2022-008", "2022-111", "2022-222", "2022-555", "2022-151"], columns=["column_of_interest"])
df["column_of_interest"] = df['column_of_interest'].apply(lambda x: '''<a href="{{% url 'columndetails' {0} %}}">{0}</a>'''.format(x)
df_html = generate_html(df)
context={"df" : df_html}

def generate_html(dataframe: pd.DataFrame):
    # get the table HTML from the dataframe
    table_html = dataframe.to_html(table_id="table", escape=False)
    # construct the complete HTML with jQuery Data tables
    # You can disable paging or enable y scrolling on lines 20 and 21 respectively
    html = f"""
    {table_html}
    <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.min.js"></script>
    <script>
        $(document).ready( function () {{
            $('#table').DataTable({{
                // paging: false,    
                // scrollY: 400,
            }});
        }});
    </script>
    """
    # return the html
    return html

views.py

def column(request):
    context = get_context(request)
    return render(request, "database/column.html", context)

def columndetails(request, column_of_interest):
    return render(request, "/columndetails.html")

urls.py

urlpatterns = [
    path('columndetails/<str:column_of_interest>/', views.labrequest_details, name="columndetails")]

toprocess.html

{% extends "database/layout.html" %}
{% load static %}
{% block body %}
<link href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.min.css" rel="stylesheet">
<br />
<div style="float: left;" class="container" id="labrequestoverview">
{{ df|safe }}
</div>

Все отображается нормально, и HTML отображается почти как положено, однако HTML не отображается Django: enter image description here

Request URL:    http://127.0.0.1:8000/%7B%25%20url%20'columndetails'%202022-007%25%7D
The current path, {% url 'columndetails' 2022-007%}, didn’t match any of these. 

Можно ли сделать так, чтобы Django отображал этот HTML так, как он задумал, а не просто пересылал его как необработанный HTML?

По вашему мнению, вы не можете использовать {% url '' %}.

Для динамического разрешения URL в вашем utils.py используйте build_absolute_uri. Вы также можете комбинировать это с reverse() следующим образом (примечание: вам придется передать объект запроса):

request.build_absolute_uri(reverse('columndetails', args=('2022-007', )))
Вернуться на верх