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

179
Visualizações
python single and multiple onclick button operations

How do i trigger an operation if a button is clicked for the first time , but if pressed again do extra thing.

if request.method == 'POST':   # if i press a button on the client side, (obj_list) return something like this [0.3, 2.32, 1.22] passed here through ajax (no problem here)
    x = 1
    obj_db = []
    for obj_items in obj_list:     
         should_sum  = False
         while not should_sum:
             x *= obj_items
             #return only two decimal numbers after float number  
             new_obj_num  = round(obj_total, 2)
             obj_db.append(new_obj_num)
             print('stored value  : ', obj_db)
            if object_selected:
              obj_db += obj_items
            else:
              should_sum = True

now, when i click a button i need the obj_list data to get multiplied, and store the results in obj_db(which i've done). But when i click again (from client side), i need to multiply but sum with the previous stored results. Any Suggestions ??!

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

0

As we talked in the comments you need to save your counter to know how many times anyone clicked.

# try to read the counter stored in a file 
try:
    f = open("counter.txt", "r")
    data_returned_as_str = f.read()
    counter = int(data_returned_as_str)
except FileNotFoundError as e:
     counter = 0 

# do your stuff

counter += 1
f = open("counter.txt", "w") # use write to overwrite the last content
f.write(str(counter))
f.close()

print(counter)

If you also need the previous data write another file to read that.

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