Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

71
Visualizações
Append table with Django URL tag JQuery

I have a table I am appending with user details and want to add a Django URL tag to the row and grab the primary key in the tag.

something like this:

function putTableData(response) {
    let row;
    $("#table_body").html("");
    if (response["data"].length > 0) {
        $.each(response["data"], function (a, b) {
            row = `<tr>
                        <td>${b["first_name"]} ${b["last_name"]}</td                               
                        <td>${b["phone"]}</td>                   
                        <td>
                            <a onclick='console.log("${b["pk"]}")' data-url="{% url 'users:edit' user.${b["pk"]} %}">
                            </a>                     
                        </td>
                    </tr>`;

                $("#table_body").append(row)

The onclick console log is printing the users primary key, but when I try to add the data url tag, I get "Could not parse the remainder ${b["pk"]}

How would I make this work?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I was able to solve with:

function putTableData(response) {
let row;
$("#table_body").html("");
if (response["data"].length > 0) {
    $.each(response["data"], function (a, b) {
        row = `<tr>
                    <td>${b["first_name"]} ${b["last_name"]}</td                               
                    <td>${b["phone"]}</td>                   
                    <td>
                        <a data-url="/users/${b["pk"]}/edit">
                        </a>                     
                    </td>
                </tr>`;

            $("#table_body").append(row)
about 4 years ago · Juan Pablo Isaza Relatório

0

Try this:

$.each(response["data"], function (a, b) {
    data_url = "{% url 'users:edit' 1 %}".replace(1, b["pk"])
    row = `<tr>
                    <td>${b["first_name"]} ${b["last_name"]}</td                               
                    <td>${b["phone"]}</td>                   
                    <td>
                        <a onclick='console.log("${b["pk"]}")' data-url="+data_url+">
                        </a>                     
                    </td>
                </tr>`;

    $("#table_body").append(row)
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda