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

596
Visualizações
Stop reload and display processed form results using Flask, AJAX, dynamic fields, and submit

I'm working on a project and I'm trying to make sure that what I'm doing even makes sense conceptually or if there is some other way to go about this. Whatever I'm trying is not working. Background: I'm good with Python and know pretty much no JavaScript, but I'm muddling through.

I'm building a Flask app that will take in and submit information about sizes from a form, will process it using Python, and will display the results on the same page. I got that working. I wanted to add dynamic fields, so a user can click to add another size. I got that working as well, and I can see in the output on the page that the function in Python is working with this additional input.

Here's the issue: when I click submit, the page reloads and the dynamic fields disappear, even though the results are still displayed below. This is pretty much a UX issue: if someone made a typo the first time, they would have to go back and add all of the fields and enter all of the info again. Plus, they wouldn't be able to see what they originially added.

I've read posts on submitting the info without reloading the page. I got that to work, but then I wasn't able to display the results of the function beneath the entry fields, since the page needed to reload, running the .py file again, in order to do that. Then I read about AJAX, which would display the input asynchronously on the original page, avoiding the page reload. However, I need the info to be processed in my .py file that has all the Flask code, and doing that, the page reloads when I use render_template() and the dynamic fields go away. Maybe there's some other way to add the Python into AJAX?

Two options I've ruled out: I know it's possible to just write a processing function in JavaScript, but this one is a little complicated and requires external libraries, so I really need the Python. Second, I was able to stop the original page from reloading and get the output into a new tab. This is not my favorite option from a UX perspective.

Is Jinja a thing that would be helpful here?

I feel like what I'm trying to do has to be possible somehow, but I'm totally missing how to do it. I think the method above can't logically work given the order in which these processes have to run. Any corrections of or comments on the above would be greatly appreciated!

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