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

572
Vistas
How to pass the id of the html button to python file by using django?

I have the following code in my HTML file that is to created the dynamic button.

  {% for i in loop_times %}
 <button type="submit" class="'btn btn-lg" name="{{ i }}" id="{{ i }}" onclick="alert(this.id)" formmethod="post"><a href="{% url 'button' %}">{{i|safe}}</a></button><br><br>
  {% endfor %}

This button has the url link which link to urls.py:

  url(r'^button',views.data, name='button'), 

The id of this buttons will dynamically created based on hw many product I have and now I want get the id of the particular buttons to pass to the python file in order for me to used the id to do analysis, so I have the following code in my view.py file

 labelid = request.GET[("id", False)]   

Anyone have idea on how to pass id of the dynamically buttons to my view.py, because above code not able to run, I'm very new to python and don't have any basic for my programing background hope that I can get some idea here, thanks

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Try using this:

labelid = request.GET.get("id", False)

instead of this:

labelid = request.GET[("id", False)]

Your current method is trying to get ("id", False) as a dictionary value, but obviously that's not what you are trying to do.

The way I suggested will look for value id. If it cannot find it, then labelid will be set to False.

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