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

284
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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