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

165
Vistas
How to connect python to javascript properly using Flask AJAX

I am learning about python and i need to send some data that i got from twitter api using tweepy. From python to javascript. I tried using Flask and ajax but i don't know why it does't work This is my python file i ran it before using flask print(text) and it works perfectly in console, but i need to send them to javascript to display them in html

This is my python file called twitter.py

from flask.typing import AppOrBlueprintKey
import tweepy
from flask import Flask, render_template,jsonify

access_token="token"
access_token_secret="secret"

api_key="key"
api_key_secret="secret"

auth =tweepy.OAuthHandler(consumer_key=api_key,consumer_secret=api_key_secret)
auth.set_access_token(access_token,access_token_secret)

api=tweepy.API(auth,wait_on_rate_limit=True)


hashtag = input("Enter hashtag: ")
tweets = tweepy.Cursor(api.search_tweets,q=hashtag,include_entities=True).items(1)

for tweet in tweets:
    text = tweet.text
    
application = Flask(__name__)

@application.route('/get_tweets',method=['POST'])
def gettweets():
    text = tweet.text
    return jsonify('',render_template('justTweet.php',x=text))
@application.route('/')
def homepage():
    return render_template('nuevo.php',x=text)
application.run()

HTML WITH JS just to try called nuevo.php

<div id="tweet">
  {{x}}
</div>
 <script>
  function getTweet(){
    $.ajax({
      url:"/get_tweets",
      type:"POST",
      dataType:"json",
      success: function(data){
        $(justTweet).replaceWith(data)
      }
    })
  }
  console.log(getTweet());
</script> 

Also i saw i had to create a new file to receive data before sending to main file php or html justTweet.php

<div id="tweet">
    {{x}}
</div>
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