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

573
Visualizações
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 Respostas
Responde à pergunta

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 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