Joke Application Project Using Django Framework
Last Updated :
20 May, 2025
We will create a simple Joke application using Django. By using the pyjokes package, we’ll build a web app that generates and displays random jokes. We’ll go step-by-step to set up the project, configure the views, and render jokes dynamically on the homepage.
Install Required Packages
First, install Django and the pyjokes package using pip:
pip install django
pip install pyjokes
Create the Django Project
Prerequisites:
Create a new Django project:
django-admim startproject jokeapp
cd jokeapp
python manage.py startapp main
The directory structure should look like this :
Update settings.py
In jokeapp/settings.py, add the main app to the INSTALLED_APPS list:

Create urls.py in the Main App
Inside the main folder, create a new file urls.py:
main/urls.py:
Python
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("main.urls")),
]
Update urls.py in the Project
Edit the jokeapp/urls.py to include the main app's URLs:
jokeapp/urls.py:
Python
from django.urls import path
from .views import *
urlpatterns = [
path("", home, name="home"),
]
Create views.py for Joke Logic
Edit the views.py file in the main app to get a joke from the pyjokes package:
main/views.py:
Python
from django.shortcuts import render,HttpResponse
import pyjokes
def home(request):
joke=pyjokes.get_joke()
return render(request,"main/index.html",{"joke":joke})
Create Templates for Rendering the Joke
Create the folder structure for templates inside the main app:
main/templates/main/index.html
Inside the main/templates directory, create another directory called main, and inside that folder, create the index.html file.
HTML
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h3>{{joke}}</h3>
</body>
</html>
Run the Server
Once everything is set up, start the server again:
python manage.py runserver
Output
Random joke displayed each time you refresh the page!
Similar Reads
Joke App using Bottle Framework - Python There are many frameworks in python which allows you to create webpage like bottle, flask, django. In this article you will learn how to create simple app bottle.Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no depende
2 min read
Django Authentication Project with Firebase Django is a Python-based web framework that allows you to quickly create efficient web applications.. When we are building any website, we will need a set of components: how to handle user authentication (signing up, signing in, signing out), a management panel for managing our website, how to uploa
7 min read
Quiz Application using Django In this article, we will create the Django Quiz Application generally the Django Quiz App is a versatile and interactive web application designed to revolutionize learning and assessment. Created to address the need for engaging and adaptable online quizzes, it offers educators, businesses, and indi
6 min read
Voting System Project Using Django Framework Project Title: Pollster (Voting System) web application using Django frameworkType of Application (Category): Web application.Introduction: We will create a pollster (voting system) web application using Django. This application will conduct a series of questions along with many choices. A user will
13 min read
Tip Calculator Project Using Django In this article, we will guide you through the process of creating a Tip Calculator Project using Django. This interactive project requires users to input the bill amount, the desired percentage for the tip, and the number of people splitting the bill. The application will then compute and display t
6 min read