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

188
Visualizações
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 à 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