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

287
Vistas
How to render template sent as response from Flask app in ajax?

I'm working with Python Flask application that uses basic html and javascript for the web part.

I'm sending data from UI to the backend using ajax post request. After processing of data, from the Python flask app I'm returning the response with render_template. But I'm not able to understand how that can be rendered using ajax on the web browser.

The python flask API returns this:

    @app.route("/execution_pipeline", methods=['POST', 'GET'])
def execution_pipeline():
    try:
        if request.method == 'POST':
            inputMap = request.get_json()
            print(inputMap)
            ###I have my code here###                                                               
            return render_template('demo.html', location=minio_results_file_location)
           

    except ReferenceError as e:
        return "It is a {} Provide proper referaece of file path"

The "demo.html" is a template in the code directory which i want to load on successful execution

And The ajax function is as follows:

$.ajax({
            type: "POST",
            url: "execution_pipeline",
            data: JSON.stringify(data),
            contentType : "application/json",
            success: function(response) {
                 window.location.href = response.redirect;
            }
        });

But on the web page, where we try to load this Ajax response, i'm getting URL not found.

Is there any solution to this?Or am i doing anything wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Import jsonify and url_for from flask:

from flask import jsonify, url_for

And try returning like this to the ajax call:

@app.route("/execution_pipeline", methods=['POST', 'GET'])
def execution_pipeline():
    try:
        if request.method == 'POST':
            inputMap = request.get_json()
            print(inputMap)
            ###I have my code here###                                                               
            return jsonify({'redirect': url_for('demo.html', location=minio_results_file_location)})
           

    except ReferenceError as e:
        return "It is a {} Provide proper referaece of file path"
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