Application Programming Interface abbreviated as API, are widely used nowadays. API basically provides an interface that allows multiple applications to communicate or share data with each other. When you use an application like Facebook to send an instant message or check weather using a weather forecasting application in your mobile phone, you are using an API. Now you must get at least a little bit of idea about API’s , how big its use is and can provide you data from anywhere, you can even create your own weather forecasting app. You must be wondering How to display API response in HTML.

Display API data in Django Template

As a Full Stack Developer you must know how to deal with API’s. Display API data in Django Template is one of the most common use cases of Django Rest Framework. You might encounter the time when you need to use API data in your projects. In this blog, we are going to learn How to display API response in HTML using Django Template. So buckle up yourself and get started to create a small web application using Django and display API data in your webapp. Here we are going to use COVID-19 API and will display the list of countries from that data.

Display API data

Step 1. Create Django Project

We are first going to create a django project, an app inside that project and then going to install requests, which will play a major role.

  1. Create a Django project.
django admin startproject blogdisplayapi

2. Create app in that django-project.

python startapp displayapi

3. Install requests  (Request rest framework extends the standard httprequest that provides flexible request parsing which helps user to treat requests with JSON data or other media types in the same way that you would normally deal with form data.)

pip install requests

4. Add your app name in installed apps.


Step 2. Add files and Folder to the Django Project

We need to create a template folder in the django folder and a file in the app folder.

  1. Create a new folder in the django folder(here, blogdisplayapi folder) save it with the name template.
  2. Add the path for this template folder in blogdisplayapi > .

import os
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'template')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

3. Create a new file in the app folder(here, display api) save it with the name .

4 . Add path for this file in blogdisplayapi > .

from django.contrib import admin
from django.urls import path,include
urlpatterns = [

Step3. Fetch API data and Display

  1. Create a function in displayapi (app_name)>, where we are going to import requests and fetch the data from the given api and pass it to the html page.

Link for the COVID API which contain countries name :-

from django.shortcuts import render
import requests
# Create your views here.
def index(request):
    return render(request,'index.html',{'response':response})

2. Create a html file in the template folder blogdisplayapi (your_django_folder)>template(folder)>index.html, where we are going to display API response in HTML.


    <title>API Display</title>
    <h1>List of countries</h1>
    {% for i in response %}
    <strong>{{i.Country}} ,</strong>
    {% endfor %}

3. Provide path for the function in view to the urls file in displayapi (your_app_name)>

from django.urls import path
from . import views
urlpatterns = [

Output :-

COVID API- list of countries

Quick Revision

  1. Create your django project folder.
  2. Create an app folder in the django project folder.
  3. Install requests.
  4. Add template folder in the django folder and provide its path in django_folder > .
  5. Create a file named as in the app folder and provide its path in django_project >
  6. Make a function for the index html page in app_folder >
  7. Add html code for the  in django_project > template > index.html.
  8. Add path of index html page in app_folder >

GitHub link :-