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

247
Vistas
How can I access the return value of a Flask route within a Javascript file?

The problem I'm having is accessing the value within the return statement in the flask route (resp["login"]). I'm trying to use this value in a javascript file and use it as a query parameter. But whenever i try the console.log() in the javascript file I get a promise object. But I am not able to find where I could find the value coming in from the Flask app. I thought it would be within the response object below but no such luck.

@app.route('/route', methods=['GET', 'POST'])
@cross_origin(supports_credentials=True)
def handle_callback():

    if request.method == 'POST':

        payload = {
            blahhh
        }
        headers = {'Accept': 'application/json', 'Access-Control-Allow-Origin': '*'}
        req = requests.post(token_url, params=payload, headers=headers)
        # make another request after this using access token with updated header field 
        resp = req.json()

        if 'access_token' in resp:
            oauthHeader = "token " + resp['blahhh']
            headers = {'Authorization': oauthHeader}
            access_token_url = 'https://blahhh.com'
            r = requests.get(url=access_token_url, headers=headers)
            resp = r.json()
            return resp["login"]
        else:
            return "error", 404
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const codeGit = urlParams.get('code')

const sub = {codeGit};
 

const res = fetch('http://localhost:4000/route', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'code': codeGit
    },
    credentials: 'include'
}).then(response => {
    if(response.status == 200){
        console.log('Success! ' + response.json() )
    }
}).catch(error => {
    console.log('error with access token req!')
})

console.log(res)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

response.json() return a promise

Return value: A Promise that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number...

.then(response => {
    if(response.status == 200){
        return response.json();
    } else {
        // handle this somehow
    }
}).then(json => {
    console.log('Success! ' + JSON.stringify(json))
}).catch(error => {
    console.log('error with access token req!')
})
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