The Wayback Machine - https://web.archive.org/web/20241001021850/https://www.geeksforgeeks.org/python-django-news-app/
Open In App

Python | Django News App

Last Updated : 14 Dec, 2020
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Django is a high-level framework which is written in Python which allows us to create server-side web applications. In this article, we will see how to create a News application using Django. 
We will be using News Api and fetch all the headline news from the api. Read more about the api here news api.
Do the Following steps in command prompt or terminal: 
 

Open the newsproject folder using a text editor. The directory structure should look like this 
 

Create a “templates” folder in your newsapp and it in settings.py
Settings .py 
 

In views.py –
In views, we create a view named index which takes a request and renders an html as a response. Firstly we import newsapi from NewsApiClient. 
 




# importing api
from django.shortcuts import render
from newsapi import NewsApiClient
  
# Create your views here. 
def index(request):
      
    newsapi = NewsApiClient(api_key ='YOURAPIKEY')
    top = newsapi.get_top_headlines(sources ='techcrunch')
  
    l = top['articles']
    desc =[]
    news =[]
    img =[]
  
    for i in range(len(l)):
        f = l[i]
        news.append(f['title'])
        desc.append(f['description'])
        img.append(f['urlToImage'])
    mylist = zip(news, desc, img)
  
    return render(request, 'index.html', context ={"mylist":mylist})


 
Create a index.html in templates folder. 
 

html




<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<!-- Optional theme -->
  </head>
  <body>
    <div class="jumbotron" style="color:black">
  
      <h1 style ="color:white">
   Get The latest news on our website
      </h1>
  
    </div>
  
  
    <div class="container">
      {% for new, des, i in mylist %}
              <img src="{{ i }}" alt="">
              <h1>news:</h1> {{ new }}
              {{ value|linebreaks }}
  
              <h4>description:</h4>{{ des }}
              {{ value|linebreaks }}
  
      {% endfor %}
    </div>
  
  </body>
</html>


 
Now map the views to urls.py 
 




from django.contrib import admin
from django.urls import path
from newsapp import views
  
urlpatterns = [
   path('', views.index, name ='index'),
    path('admin/', admin.site.urls),
]


Your output of the project should look like this – 
 



Previous Article
Next Article

Similar Reads

Build an Application to extract news from Google News Feed Using Python
Prerequisite- Python tkinter In this article, we are going to write a python script to extract news articles from Google News Feed by using gnewsclient module and bind it with a GUI application. gnewsclient is a python client for Google News Feed. This API has to installed explicitly first in order to be used. Installation The following terminal co
2 min read
Fetching top news using News API
News API is a simple JSON-based REST API for searching and retrieving news articles from all over the web. Using this, one can fetch the top stories running on a news website or can search top news on a specific topic (or keyword). News can be retrieved based on some criteria. Say the topic (keyword) to be searched is 'Geeksforgeeks' or might be co
5 min read
A simple News app with Tkinter and Newsapi
Prerequisites: Tkinter Tkinter is a very famous python library for building a desktop app for windows and UNIX based OS. The idea here is to generate a python code to build a news app with Tkinter. You can very easily get yourself an API key from newsapi.org . ApproachImport modulesCreate a screen with a titleAdd labelsAdd buttonsCreate a textarea
3 min read
How to Build a News App Using WebView Controller in Android Studio?
In this article, we are going to make a News App with help of a WebView Controller in Android Studio. By making this application we will learn how to access Internet Permission in our android application and how to use WebView with its class named WebView Controller. After making this application you will also be aware of Navigation Drawer activity
7 min read
How to Build a Stock Market News Android App using Retrofit?
Building a stock market news app can be a great way to stay informed about the latest developments in the financial world. This article will explore how to build a simple news app using Kotlin and Retrofit. A sample video is given below to get an idea about what we are going to do in this article. [video mp4="https://media.geeksforgeeks.org/wp-cont
12 min read
News App using React
News App using React JS uses React's basic principles to fetch the latest news from a News API and show them to users based on their interests. It's a simple project to create an interactive and personalized news-viewing experience. Preview of final output: Let us have a look at how the final output will look like. Prerequisites:React JSJSXBasic of
4 min read
Create a News Reader app using React-Native
Creating the News Reader application using React-Native language is an exciting project. Using this project, the users can read the news in the application itself, by filtering them according to the categories as per their interest. In this article, we will develop the complete News Reader application to fetch real-time news from News API. Preview
5 min read
Newspaper scraping using Python and News API
There are mainly two ways to extract data from a website: Use the API of the website (if it exists). For example, Facebook has the Facebook Graph API which allows retrieval of data posted on Facebook.Access the HTML of the webpage and extract useful information/data from it. This technique is called web scraping or web harvesting or web data extrac
4 min read
Implementing News Parser using Template Method Design Pattern in Python
While defining algorithms, programmers often neglect the importance of grouping the same methods of different algorithms. Normally, they define algorithms from start to end and repeat the same methods in every algorithm. This practice leads to code duplication and difficulties in code maintenance – even for a small logic change, the programmer has
4 min read
Scrape most reviewed news and tweet using Python
Many websites will be providing trendy news in any technology and the article can be rated by means of its review count. Suppose the news is for cryptocurrencies and news articles are scraped from cointelegraph.com, we can get each news item reviewer to count easily and placed in MongoDB collection. Modules Needed Tweepy: Tweepy is the Python clien
5 min read
Daily Latest News webapp Using PyWebio in Python
In this article, we are going to create a web app to get gaily News Using PyWebio As we all download an app for receiving daily news but as a python lovers we try to do all these things via a python script. So here is a python script that notifies the daily news. In this script, we will create a web app using pywebio which shows all the top headlin
5 min read
How to get the Daily News using Python
In this article, we are going to see how to get daily news using Python. Here we will use Beautiful Soup and the request module to scrape the data. Modules neededbs4: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. This module does not come built-in with Python. To install this type the below command in the termi
3 min read
Web Scraping Financial News Using Python
In this article, we will cover how to extract financial news seamlessly using Python. This financial news helps many traders in placing the trade in cryptocurrency, bitcoins, the stock markets, and many other global stock markets setting up of trading bot will help us to analyze the data. Thus all this can be done with the help of web scraping usin
3 min read
Python Desktop News Notifier in 20 lines
To get started with the Desktop News Notifier, we require two libraries: feedparser and notify2. Give following command to to install feedparser: sudo pip3 install feedparser For installing notify2 in your terminal: sudo pip3 install notify2 Feedparser will parse the feed that we will get from the URL. We will use notify2 for the desktop notificati
2 min read
Automatic News Scraping with Python, Newspaper and Feedparser
The problem we are trying to solve here is to extract relevant information from news articles, such as the title, author, publish date, and the main content of the article. This information can then be used for various purposes such as creating a personal news feed, analyzing trends in the news, or even creating a dataset for natural language proce
3 min read
Facebook News Feed Algorithm
Ever noticed how the news feeds of the multitude social networking sites and applications differ drastically from one person to another? Each feed seems to have been tailored to an individual to deliver content that has been predicted in order to provide the ideal platform for users. Predicted being the key word here makes one infer that there is p
4 min read
Project Idea - Searching news from Old Newspaper using NLP
We know that the newspaper is an enriched source of knowledge. When a person needs some information about a particular topic or subject he searches online, but it is difficult to get all old news articles from regional local newspapers related to our search. As not every local newspaper provides an online search for people.In this article, we will
5 min read
EdgeRank Algorithm - Algo behind Facebook News Feed
Every time you open your Facebook account, the first thing you see is your newsfeeds. All likes, comments, tags, status updates, shares and many more such things by your friends. Ever wondered how you get these feeds in the way that you find it interesting and not like any random order? The answer is that Facebook employs a machine learning algorit
3 min read
Real Time News Aggregator with NodeJS and ExpressJS
In this article, we will create a real time news application with the help of NodeJS and ExpressJS. This article consists of several main functionalities. First, we will display the news article. Then we have implemented the search functionality to search news based on the title of the news. Then we get the feature to have sorting by date and we ca
4 min read
Flask NEWS Application Using Newsapi
In this article, we will create a News Web Application using Flask and NewsAPI. The web page will display top headlines and a search bar where the user can enter a query, after processing the query, the webpage will display all relevant articles (up to a max of 100 headlines). We will create a simple user interface using HTML and bootstrap. You can
7 min read
7 Best News Apps for iOS and Android
The stocks fall, political parties change, and the war begins; everything happens in a day. Hence living in such a chaotic world where you never know what happens next, you can't just sit and wait for the morning newspaper to update you all. That's why, staying updated has become crucial for all. For this, online news apps come as a great solution.
10 min read
News Media Platform with MERN Stack
In this article, we’ll walk through the step-by-step process of creating a News Media Platform using the MERN (MongoDB, ExpressJS, React, NodeJS) stack. This project will showcase how to set up a full-stack web application where users can view a news article, add a new news article, and delete one. Preview of final output: Let us have a look at how
8 min read
Weather app using Django | Python
In this tutorial, we will learn how to create a Weather app that uses Django as backend. Django provides a Python Web framework based web framework that allows rapid development and clean, pragmatic design. Basic Setup - Change directory to weather – cd weather Start the server - python manage.py runserver To check whether the server is running or
2 min read
Django App Model - Python manage.py makemigrations command
According to documentation, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into. makemigrations are run thro
2 min read
Adding Tags Using Django-Taggit in Django Project
Django-Taggit is a Django application which is used to add tags to blogs, articles etc. It makes very easy for us to make adding the tags functionality to our django project.Setting up Django Project Installing django-taggit pip install django-taggitADD it to Main Project's settings.py file C/C++ Code INSTALLED_APPS = [ 'django.contrib.admin', 'dja
2 min read
How to customize Django forms using Django Widget Tweaks ?
Django forms are a great feature to create usable forms with just few lines of code. But Django doesn't easily let us edit the form for good designs. Here, we will see one of the ways to customize Django forms, So they will look according to our wish on our HTML page. Basically we will check the methods to include our own custom css, classes, or id
3 min read
Styling Django Forms with django-crispy-forms
Django by default doesn't provide any Django form styling method due to which it takes a lot of effort and precious time to beautifully style a form. django-crispy-forms solves this problem for us. It will let you control the rendering behavior of your Django forms in a very elegant and DRY way. Modules required:django : django installdjango-crispy
1 min read
Integrating Django with Reactjs using Django REST Framework
In this article, we will learn the process of communicating between the Django Backend and React js frontend using the Django REST Framework. For the sake of a better understanding of the concept, we will be building a Simple Task Manager and go through the primary concepts for this type of integration between React js and Django. Reactjs in a nuts
15+ min read
How to Fix Django "ImportError: Cannot Import Name 'six' from 'django.utils'"?
After Django 3.0, django.utils.six was removed. The "ImportError: Cannot Import Name 'six' from 'django.utils'" error occurs because of the dependency issue. This happens because when the project tries to use something that’s no longer available. Don’t worry—it’s easy to fix. We’ll explain why this error happens and give you simple steps to solve i
3 min read
How to Create an App in Django ?
Prerequisite - How to Create a Basic Project using MVT in Django? Django is famous for its unique and fully managed app structure. For every functionality, an app can be created like a completely independent module. This article will take you through how to create a basic app and add functionalities using that app.For example, if you are creating a
4 min read
Article Tags :
Practice Tags :