Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!