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

189
Vistas
Sending data directly to index.html from Flask render_template

I'm using BeautifulSoup to scrape data from a website. I want to display the extracted data on a separate HTML page.
Unfortunately, to send said data, I'm using Flask, which only allows me to send data to render_template, which as far as I understand requires your HTML files to be in a "template" folder.
I want the data to be displayed within a <p> element on index.html, which I don't want to be in another folder.

Here's the code that runs on main.py
(I'm running everything on a server)

from flask import Flask, render_template
app=Flask(__name__)
from bs4 import BeautifulSoup
import requests

#Scraping starts
url = "https://example.com" 
req = requests.get(url)
bs0bj = BeautifulSoup (req.text, "html.parser")

data=bs0bj.find_all('div', {"class": "exampleClass"})
data=data[0].text 
data=data.strip()

#Send to index.html
@app.route('/')
def home():
    return render_template('index.html',data=data)

You should be able to display the received data in html with something like <p>{{data}}</p>

I can't seem to find a way to send the data from main.py to index.html, and how to receive the data from main.py inside index.html
Other options that don't use Flask are also welcome.

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