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

180
Vistas
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 Respuestas
Responde la pregunta

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