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

199
Visualizações
How can I keep user input on form on a failed post request in flask

I am building a website that will accept user input in 7 fields, one of them is a list of stocks (can be up to 100). One of the fields the user should input is a target of annual rate of return.

The issue I am having is that if the target of annual rate of return failed (it is larger than the max return) I am flashing the user with a message, and redirecting to the form, but I lose all pre entered input feilds the user submitted.

What I would like to do is to keep all the input the user submitted and flash the message under the "target of annual rate of return" field in the form.

What I have so far is on HTML:

<h3> Please enter target annual rate of return</h3>
    <div class="form-group">
        <input autocomplete="off" autofocus class="form-control" name="return" placeholder="rate of return" type="number">%
    </div>
    <button onClick="this.form.submit(); this.disabled=true; this.value='Sending…'; " class="btn btn-primary" type="submit">Build</button>

on the app.py I have:

ef = EfficientFrontier(mu, S, weight_bounds=(None, None))
    ef.add_objective(objective_functions.L2_reg)
    try:
        ef.efficient_return(target_return=(float(request.form.get("return"))/100), market_neutral=True)
    except pypfopt.exceptions.OptimizationError:
        flash('Target annual rate of return is too high for this portfolio, please consider using a lower rate')
        return redirect("/build")

so hopefully I will have the flash appearing and the form input intact when except "pypfopt.exceptions.OptimizationError:" is triggered.

Thanks!

about 4 years ago · Juan Pablo Isaza
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