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

380
Vistas
How to get data from one form by submit if there are several forms AJAX FLASK

I need to get data from one form by clicking the button when there are multiple forms, but I only get data from the first form. I understand why this doesn't work, but I don't understand how to make the data come from a specific form.

Picture and code down below

html forms and ajax code

flask code

FLASK


@app.route('/product')
def product():
    return render_template('product.html',
                           products=dbase.get_products_announce(),
                           check_authenticated=check_authenticated)

@app.route('/render_user_adding_item', methods=["POST"])
def render_user_adding_item():
    data_get = request.form.to_dict(flat=True)
    print(data_get)

HTML JS

{% block content %}
{{ super() }}



<div class="productlists">
{% for p in range(products | length) %}

    <div class="list-products">
        <div class="list-element">
        <a href="{{ url_for('show_product', alias=products[p][7])}}"><img class="col-3" src="\static\images\productImg\{{products[p][8]}}"  width="380" height="510"></a>
            
            <div class="list-element-description">
            


                <form id="{{ products[p][6] }}">

                    <div class="buttonbuy-2">
                    <button type="submit" class="buttonbuy">Купить</button>
                        <input type="hidden" id="order_id" value="{{products[p][0]}}">
                        <input type="hidden" id="user_id" value="{{current_user.get_id()}}">
                    </div>  

                </form>



           </div>
        </div>
    </div>
{% endfor %}
</div>


<script>
$(document).ready(function() {
    $('form').on('submit', function(event) {
        $.ajax({
            data : {
                order_id : $('#order_id').val(),
                user_id : $('#user_id').val()
            },
            type : 'POST',
            url : '/render_user_adding_item'
        })


        event.preventDefault();
    });
});
</script>
{% endblock %} 

I apologize if I wrote something wrong, this is my first question

over 4 years ago · Santiago Trujillo
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