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

179
Vistas
How can I process an Excel file for download without page refreshing using Flask and JavaScript?

I'm writing a Flask application that allows a user to select a project and project version from two dropdowns, then process and download an Excel document with information relevant to the selections made. I've been able to make this work, but my code causes the browser to show the refresh animation until the file is fully processed and begins to download. Ideally, I'd like the browser to process the file without showing the refresh animation. My current code is as follows:

The user makes the selections and hits the export button using this HTML:

<form method="POST" action="">
    <h2 class="text-center">Select Project and Version</h2>
    {{ form.hidden_tag() }}
    <div class="form-group">
        {{ form.projects(class="form-control-sm") }}
        {{ form.versions(class="form-control-sm") }}
    </div>
    <div class="form-group">
        <button type="button" id="export" class="btn-primary form-control">Export</button>
    </div>
</form>

Upon hitting export, the following JavaScript is ran:

let export_button = document.getElementById('export')

export_button.onclick = function() {
    project_index = project_select.value;
    version_index = versions_select.value;

    location.href = '/' + project_index + '/' + version_index;
}

The following route is called to process then send the file for download:

@app.route("/<project_index>/<version_index>")
def export(project_index, version_index):
    # Call functions to process file
    return send_file(output, attachment_filename="testing.xlsx", as_attachment=True)

The processing of the file includes various API calls that cause the process to take up to roughly 30 seconds. Is there a way I can make this work without having the browser show the refresh animation? Perhaps using AJAX?

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