Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

308
Vistas
Clickable Flask table storing the clicked value

Following some flask tutorials I've built a table with clickable rows. Upon clicking any Index column value, user is redirected to a new route named after the clicked index value e.g. @app.route(/1). This however, is not what exactly what I want and I'm struggling in adjusting the app to my needs.

I would like user to be moved to a route 'XYZ' no matter the value clicked. Then, the 'XYZ' route should print/store the Index value clicked by user.

How can I change the HTML anchor value to static and at the same time store the clicked value?

HTML

{% extends "bootstrap/base.html" %}
{% block content %}
<head>

  <script type="text/javascript" src="{{ url_for('static', filename='js/click_table.js') }}"></script>
</head>
    <table id="data" class="table table-striped">
      <thead>
        <tr>
          <th>Index</th>
          <th>Playlist Name</th>
          <th>Playlist ID</th>
        </tr>
      </thead>
      <tbody>
        {% for index, row in playlists_df.iterrows() %}
          <tr>
            <td><a href="{{ row['index'] }}"> {{ row['index'] }} </a></td>
            <td>{{ row['name'] }}</td>
            <td>{{ row['id'] }}</td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
</form>
{% endblock %}

JS

$(document).ready(function() {

    $('#data tr').click(function() {
        var index = $(this).find("a").attr("href");
        if(index) {
            window.location = index;
        }
    });
});

Python part I'm going for:

@app.route('/XYZ')
def get_clicked_index_value():
    # request index_value from JS
    return Index
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda