Django REST Framework is a robust and flexible toolkit for building Web APIs. It is written in python and allows the user to create some cool and awesome web applications. In this blog we will learn how to create a joke app from scratch in Django from scratch. This will be another good project for you to show. Now coming back to our project we will be using pyjokes library for generating jokes. Pyjokes actually generate one line jokes, so everytime you refresh your page a new joke will pop up, isn’t it cool you can use this functionality in your other projects and can make it more user friendly .

Create Joke App in Django from Scratch


Step 1. Create Django Project

We are first going to create a django project, an app inside that project and then going to install pyjokes, which will play a major role in our project.
1. Create a Django project.

django-admin startproject blog19

2. Create an app in that django-project.

python startapp jokes

3. Install pyjokes, pyjokes will provide you jokes.

pip install pyjokes

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,blog19) save it with the name template.
  2. Add the path for this template folder in blog19 > .

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, jokes) save it with the name .

4. Add path for this file in blog19 > .

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

Step3. Create Joke app

In this step we will perform main implementation. You just need to create a html file then, provide its url path and link it with the function in and then that function will provide the joke that you can render in your html file.

  1. Create a path for the index html page in jokes > .

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

2. Create a function for the index page in jokes > .

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

3. Create html file in template>index.html .


        Joke APP
    <h1 align="center"> Joke OF the Day</h1>
    <p align="center">{{jokes}}</p>

Output :-

Create Joke App in Django from Scratch
Joke 1
Create Joke App in Django from Scratch
Joke 2

Quick Revision

  1. Create your django project folder.
  2. Create an app folder in the django project folder.
  3. Install pyjokes.
  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. Add path of index html page in app_folder >
  7. Create function for the index html page in app_folder >
  8. Add html code for the  in django_project > template > index.html.

GitHub Link :-


So, we learned how to create a Joke App from scratch in Django. I hope this blog will be useful for you and helps you to understand each and every step. Hope all your doubts get cleared. Thank you.