top of page

Flask Project Help | Creating News Web App Using Flask NewsAPI


Flask Web App

In this post, we have to create a web application using flask which takes news headlines, title, and description from NewsAPI.



Here Some Basic steps to do this


Open "News.org"


Then click on top of the menu item "documentation" and then install the "newsapi".




Installing Newsapi


Now new page is open, after this click on "python", which is on left sidebar:


Click on python and install news API




pip install newsapi-python

Now login(newsapi.org) to find API key


  • Login news api site and get api


Fill details and get api like this


937985d39a6144c382769fda00067b7d

Now create python project


NewsApiFlaskApp(project name)

Now in project directory create new directory “templates” and “app.py” file


File Structure:




#---------code---------#


from flask import Flask from newsapi import NewsApiClient app = Flask(__name__) @app.route('/') def index():     newsapi = NewsApiClient(api_key="937985d39a6144c382769fda00067b7d")     topheadlines = newsapi.get_top_headlines(sources = )


#------------------------------#


Now adding source:


See in the red circle:



Now new updated code after adding source


#------------------------------code-------------------


from flask import Flask from newsapi import NewsApiClient app = Flask(__name__) @app.route('/') def index():     newsapi = NewsApiClient(api_key="937985d39a6144c382769fda00067b7d")     topheadlines = newsapi.get_top_headlines(sources = "bbc-news")     article = topheadlines['article']     desc = []     news = []     img = []     for i in range(len(article)):         myarticles = article[i]         news.append(myarticles['title'])


#---------------------------------------------------------



Where title is take from: From newapi.org


See it in red rectangle


After this Go to the templates folder and create two file "index.html" and "bcc.html"




Thanks for reading this, if you need complete custom project then you can contact us at below Gmail:


codersarts@gmail.com

Send your requirements at this.


We are providing other project-related assignments like Java, PHP, C, C++, and more other help services, if you need any other programming help then also send your quote.


bottom of page