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

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