I am currently trying to integrate this free to use 3rd Party API into my website. I am using Python which uses flask so I will be using render templates so how do I pass this data through my to my template?
below is the method within my .py class which also has requests packaged installed. NOTE: I have used an invalid API key just for security measures.
@app.route('/Api', methods=['POST'])
def index():
# BBC news api
main_url = " https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=123"
# fetching data in json format
open_bbc_page = requests.get(main_url).json()
# getting all articles in a string article
article = open_bbc_page["articles"]
# empty list which will
# contain all trending news
results = []
for ar in article:
results.append(ar["title"])
for i in range(len(results)):
# printing all trending news
print(i + 1, results[i])
return render_template('home_page.html')
if __name__ == '__main__':
app.run(debug=True)
Also how do I then display this in my html file?