

{"id":96130,"date":"2021-05-28T10:25:06","date_gmt":"2021-05-28T04:55:06","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=96130"},"modified":"2026-06-01T13:53:08","modified_gmt":"2026-06-01T08:23:08","slug":"create-quiz-application-python-django","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/","title":{"rendered":"How to Create a Quiz Web Application with Python Django"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:2579,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1mUiLol9aT1d_EodeZvZcxKWMvWHX8yp3\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601082318\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1mUiLol9aT1d_EodeZvZcxKWMvWHX8yp3\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-02 07:13:31&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-02 07:13:31&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p><strong>Quiz<\/strong> &#8211; best way to check our knowledge on a particular topic.<\/p>\n<p>We have visited a lot of quiz platforms lately, right! Ever wondered if you could develop one.<\/p>\n<p>In this article, we will guide you to develop a quiz application using Python Django. Let\u2019s see what all functionalities we will be developing in this project (for two roles &#8211; user and admin):<\/p>\n<p><strong>User:<\/strong><\/p>\n<ul>\n<li>Sign up (register)<\/li>\n<li>Login<\/li>\n<li>Quiz page (with timer)<\/li>\n<li>Result page (with score, time taken, percentage score, total questions, correct answers, wrong answers)<\/li>\n<\/ul>\n<p><strong>Admin:<\/strong><\/p>\n<ul>\n<li>Login<\/li>\n<li>Sign up<\/li>\n<li>Add Question<\/li>\n<li>Quiz Page<\/li>\n<li>Result Page<\/li>\n<\/ul>\n<h4>Project Prerequisites<\/h4>\n<p>You should have a basic knowledge of the following technologies:<\/p>\n<ul>\n<li>HTML: to display content on web page<\/li>\n<li>CSS: to style HTML document<\/li>\n<li>JavaScript: to make a timer<\/li>\n<li>Bootstrap: A front-end framework<\/li>\n<li>Python: Programming language.<\/li>\n<li>Django: Python framework<\/li>\n<\/ul>\n<p><strong>To install Django:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install Django<\/pre>\n<h3>Download Quiz App Python Code<\/h3>\n<p>Please download the source code of quiz web application: <a href=\"https:\/\/drive.google.com\/file\/d\/1mUiLol9aT1d_EodeZvZcxKWMvWHX8yp3\/view?usp=drive_link\"><strong>Quiz Web Application Python Code<\/strong><\/a><\/p>\n<h3>Steps to Build Quiz App Project<\/h3>\n<h4>1. Starting project:<\/h4>\n<p>Commands to start the project and app:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">django-admin startproject DjangoQuiz\r\ncd DjangoQuiz\r\ndjango-admin startapp Quiz<\/pre>\n<h4>2. Writing Models<\/h4>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.db import models\r\n \r\n# Create your models here.\r\nclass QuesModel(models.Model):\r\n    question = models.CharField(max_length=200,null=True)\r\n    op1 = models.CharField(max_length=200,null=True)\r\n    op2 = models.CharField(max_length=200,null=True)\r\n    op3 = models.CharField(max_length=200,null=True)\r\n    op4 = models.CharField(max_length=200,null=True)\r\n    ans = models.CharField(max_length=200,null=True)\r\n    \r\n    def __str__(self):\r\n        return self.question\r\n<\/pre>\n<p>We just need one model for this project, QuesModel.<\/p>\n<p><strong>Attributes of QuesModels:<\/strong><\/p>\n<ul>\n<li>question: This stores the question, we have also defined maximum length of the question i.e. 200<\/li>\n<li>op1: As the quiz contains Multiple choice questions. This stores option 1 value.<\/li>\n<li>op2: option2<\/li>\n<li>op3: option3<\/li>\n<li>op4: option4<\/li>\n<li>ans: This indicates which among the four options is the correct ans.<\/li>\n<\/ul>\n<p>The __str__() method returns a string representation of any object of QuesModel.<\/p>\n<p>In Django when we use Sqlite3 database, we don\u2019t have to write table definitions we just have to write models and after that, we have to run the following commands<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Py manage.py makemigrations\r\nPy manage.py migrate\r\n<\/pre>\n<h4>3. forms.py<\/h4>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.forms import ModelForm\r\nfrom .models import *\r\nfrom django.contrib.auth.forms import UserCreationForm\r\nfrom django.contrib.auth.models import User\r\n \r\nclass createuserform(UserCreationForm):\r\n    class Meta:\r\n        model=User\r\n        fields=['username','password'] \r\n \r\nclass addQuestionform(ModelForm):\r\n    class Meta:\r\n        model=QuesModel\r\n        fields=\"__all__\"\r\n<\/pre>\n<p>To access, update, create or delete entries in the database (to implement CRUD functionality), we need forms.<\/p>\n<p>Form makes it easy to implement CRUD functionality as we neither have to create forms to accept information from users nor we have to validate information manually, we can just use is_valid() method to validate the information before updating it in the database.<\/p>\n<h4>4. admin.py<\/h4>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.contrib import admin\r\nfrom .models import *\r\n \r\n# Register your models here.\r\nadmin.site.register(QuesModel)\r\n<\/pre>\n<p>Here, we are registering our model to the admin site, so that we can update or access the database from the admin panel also. But we need a superuser to access the admin site.<\/p>\n<p>To create a staff (admin) user, run the below command<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">py manage.py createsuperuser\r\n<\/pre>\n<h4>5. settings.py<\/h4>\n<p>To use javascript we have to specify the path of static files. Therefore, add the following code in settings.py<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">STATIC_URL = '\/static\/'\r\nSTATICFILES_DIRS=[BASE_DIR\/'static']\r\n<\/pre>\n<h4>6. urls.py<\/h4>\n<p>In this file we are just defining urls. To define urls:<\/p>\n<ul>\n<li>import view functions: from Quiz.views import *<\/li>\n<li>add url to urlpatterns: path(&#8216;login\/&#8217;, loginPage,name=&#8217;login&#8217;),<\/li>\n<\/ul>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\"\"\"DjangoQuiz URL Configuration\r\n \r\nThe `urlpatterns` list routes URLs to views. For more information please see:\r\n    https:\/\/docs.djangoproject.com\/en\/3.1\/topics\/http\/urls\/\r\nExamples:\r\nFunction views\r\n    1. Add an import:  from my_app import views\r\n    2. Add a URL to urlpatterns:  path('', views.home, name='home')\r\nClass-based views\r\n    1. Add an import:  from other_app.views import Home\r\n    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')\r\nIncluding another URLconf\r\n    1. Import the include() function: from django.urls import include, path\r\n    2. Add a URL to urlpatterns:  path('blog\/', include('blog.urls'))\r\n\"\"\"\r\nfrom django.contrib import admin\r\nfrom django.urls import path\r\nfrom Quiz.views import *\r\nfrom django.conf import settings\r\nfrom django.conf.urls.static import static\r\n \r\nurlpatterns = [\r\n    path('admin\/', admin.site.urls),\r\n    path('', home,name='home'),\r\n    path('addQuestion\/', addQuestion,name='addQuestion'),\r\n    path('login\/', loginPage,name='login'),\r\n    path('logout\/', logoutPage,name='logout'),\r\n    path('register\/', registerPage,name='register'),\r\n \r\n]\r\nurlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)\r\n<\/pre>\n<h4>7. views.py :<\/h4>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">from django.shortcuts import redirect,render\r\nfrom django.contrib.auth import login,logout,authenticate\r\nfrom .forms import *\r\nfrom .models import *\r\nfrom django.http import HttpResponse\r\n \r\n# Create your views here.\r\ndef home(request):\r\n    if request.method == 'POST':\r\n        print(request.POST)\r\n        questions=QuesModel.objects.all()\r\n        score=0\r\n        wrong=0\r\n        correct=0\r\n        total=0\r\n        for q in questions:\r\n            total+=1\r\n            print(request.POST.get(q.question))\r\n            print(q.ans)\r\n            print()\r\n            if q.ans ==  request.POST.get(q.question):\r\n                score+=10\r\n                correct+=1\r\n            else:\r\n                wrong+=1\r\n        percent = score\/(total*10) *100\r\n        context = {\r\n            'score':score,\r\n            'time': request.POST.get('timer'),\r\n            'correct':correct,\r\n            'wrong':wrong,\r\n            'percent':percent,\r\n            'total':total\r\n        }\r\n        return render(request,'Quiz\/result.html',context)\r\n    else:\r\n        questions=QuesModel.objects.all()\r\n        context = {\r\n            'questions':questions\r\n        }\r\n        return render(request,'Quiz\/home.html',context)\r\n \r\ndef addQuestion(request):    \r\n    if request.user.is_staff:\r\n        form=addQuestionform()\r\n        if(request.method=='POST'):\r\n            form=addQuestionform(request.POST)\r\n            if(form.is_valid()):\r\n                form.save()\r\n                return redirect('\/')\r\n        context={'form':form}\r\n        return render(request,'Quiz\/addQuestion.html',context)\r\n    else: \r\n        return redirect('home') \r\n \r\ndef registerPage(request):\r\n    if request.user.is_authenticated:\r\n        return redirect('home') \r\n    else: \r\n        form = createuserform()\r\n        if request.method=='POST':\r\n            form = createuserform(request.POST)\r\n            if form.is_valid() :\r\n                user=form.save()\r\n                return redirect('login')\r\n        context={\r\n            'form':form,\r\n        }\r\n        return render(request,'Quiz\/register.html',context)\r\n \r\ndef loginPage(request):\r\n    if request.user.is_authenticated:\r\n        return redirect('home')\r\n    else:\r\n       if request.method==\"POST\":\r\n        username=request.POST.get('username')\r\n        password=request.POST.get('password')\r\n        user=authenticate(request,username=username,password=password)\r\n        if user is not None:\r\n            login(request,user)\r\n            return redirect('\/')\r\n       context={}\r\n       return render(request,'Quiz\/login.html',context)\r\n \r\ndef logoutPage(request):\r\n    logout(request)\r\n    return redirect('\/')\r\n<\/pre>\n<p>View.py is the file which contains the main or we can say the business logic of the project as this file can only access the database and also it can pass the information to templates so that it can be displayed on the web browser.<\/p>\n<h4>Home<\/h4>\n<p>This is the most important view of our project as this method is responsible for displaying the quiz page as well as the result page.<\/p>\n<p><strong>For Quiz Page:<\/strong> It renders all the questions from QuesModel and then it just passes all the questions to home.html<\/p>\n<p><strong>For result page:<\/strong> It calculates the score by giving ten marks for every correct question and zero (i.e. no negative marking) for every incorrect question. And then it calculates the percentage score.<\/p>\n<p>Finally, it sends all these calculated values along with time elapsed, number of correct answers, number of incorrect answers to result.html. Result.html displays all this information.<\/p>\n<h4>Add Question:<\/h4>\n<p>This method is only for admin, if any user tries to access this method, the user is redirected to the home page. We are basically using the add question form in this to create a form object.<\/p>\n<p>To validate the information entered by the user we are using is_valid method and after validating the information we are adding another question in the database using save() method.<\/p>\n<h4>Result.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% extends 'Quiz\/dependencies.html' %}\r\n \r\n{% block content %}\r\n \r\n&lt;div class=\"container \"&gt;\r\n        \r\n    &lt;div class=\"card-columns\" style=\"padding: 10px; margin: 20px;\"&gt;\r\n        &lt;div class=\"card\" align=\"centre \" style=\"width: 32rem; border:5px black solid\"&gt;\r\n            &lt;img class=\"card-img-top\" src=\"http:\/\/kmit.in\/emagazine\/wp-content\/uploads\/2018\/02\/karnataka-results.jpg\" alt=\"Card image cap\"&gt;\r\n            &lt;div class=\"card-body\"&gt;\r\n                &lt;h5 class=\"card-title\"&gt;Score: {{score}}&lt;\/h5&gt;\r\n \r\n                &lt;p class=\"card-text\"&gt;Percentage: {{percent}}%&lt;\/p&gt;\r\n                &lt;p class=\"card-text\"&gt;Time Taken: {{time}} seconds&lt;\/p&gt;\r\n                &lt;p class=\"card-text\"&gt;Correct answers: {{correct}}&lt;\/p&gt;\r\n                &lt;p class=\"card-text\"&gt;Incorrect answers: {{wrong}}&lt;\/p&gt;\r\n                &lt;p class=\"card-text\"&gt;Total questions: {{total}}&lt;\/p&gt;\r\n                &lt;h5&gt;All the best for next quiz!&lt;\/h5&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n \r\n&lt;\/div&gt;\r\n \r\n{% endblock %}\r\n<\/pre>\n<p><strong>Result page:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96132\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result.png\" alt=\"quiz result\" width=\"1366\" height=\"726\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-300x159.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-1024x544.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-768x408.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-720x383.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-520x276.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-result-320x170.png 320w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>Home.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% extends 'Quiz\/dependencies.html' %}\r\n \r\n{% block content %}\r\n{% load static %}\r\n&lt;div class=\"container \"&gt;\r\n&lt;h1&gt;Welcome to DataFlair Quiz&lt;\/h1&gt;\r\n \r\n&lt;div align=\"right \" id=\"displaytimer\"&gt;&lt;b&gt;Timer: 0 seconds&lt;\/b&gt;&lt;\/div&gt;\r\n \r\n &lt;form method='post' action=''&gt;\r\n    {% csrf_token %}\r\n    {% for q  in questions%}\r\n    &lt;div class=\"form-group\"&gt;\r\n      &lt;label for=\"question\"&gt;{{q.question}}&lt;\/label&gt;\r\n    &lt;\/div&gt;\r\n    &lt;div class=\"form-check\"&gt;\r\n        &lt;div class=\"form-check\"&gt;\r\n            &lt;input class=\"form-check-input\" type=\"radio\" name=\"{{q.question}}\" id=\"gridRadios1\" value=\"option1\" checked&gt;\r\n            &lt;label class=\"form-check-label\" for=\"gridRadios1\"&gt;\r\n                {{q.op1}}\r\n            &lt;\/label&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=\"form-check\"&gt;\r\n            &lt;input class=\"form-check-input\" type=\"radio\" name=\"{{q.question}}\" id=\"gridRadios2\" value=\"option2\"&gt;\r\n            &lt;label class=\"form-check-label\" for=\"gridRadios2\"&gt;\r\n                {{q.op2}}\r\n            &lt;\/label&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=\"form-check\"&gt;\r\n            &lt;input class=\"form-check-input\" type=\"radio\" name=\"{{q.question}}\" id=\"gridRadios1\" value=\"option3\"&gt;\r\n            &lt;label class=\"form-check-label\" for=\"gridRadios1\"&gt;\r\n                {{q.op3}}\r\n            &lt;\/label&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=\"form-check\"&gt;\r\n            &lt;input class=\"form-check-input\" type=\"radio\" name=\"{{q.question}}\" id=\"gridRadios2\" value=\"option4\"&gt;\r\n            &lt;label class=\"form-check-label\" for=\"gridRadios2\"&gt;\r\n                {{q.op4}}\r\n            &lt;\/label&gt;\r\n        &lt;\/div&gt;\r\n        &lt;br&gt;\r\n    &lt;\/div&gt;    \r\n    {% endfor %}\r\n    &lt;input id='timer' type='hidden' name=\"timer\" value=\"\"&gt;\r\n    &lt;br&gt;\r\n    &lt;button type=\"submit\" class=\"btn btn-primary\"&gt;Submit&lt;\/button&gt;\r\n  &lt;\/form&gt;\r\n    {% block script %}\r\n        &lt;script&gt;\r\n \r\n            console.log('hello world')\r\n            const timer=document.getElementById('displaytimer')\r\n            console.log(timer.textContent)\r\n            const inputtag = document.getElementById('timer')\r\n \r\n            t=0\r\n            setInterval(()=&gt;{\r\n                t+=1\r\n                timer.innerHTML =\"&lt;b&gt;Timer: \" +t+\" seconds&lt;\/b&gt;\"\r\n                inputtag.value = t\r\n            },1000)\r\n        &lt;\/script&gt;\r\n    {% endblock script %}\r\n \r\n&lt;\/div&gt;\r\n{% endblock %}\r\n<\/pre>\n<p><strong>Quiz page<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96133\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home.png\" alt=\"quiz user home\" width=\"1366\" height=\"726\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-300x159.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-1024x544.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-768x408.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-720x383.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-520x276.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-user-home-320x170.png 320w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p>For admin, only the navigation bar is different, it has one button for adding questions.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96134\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home.png\" alt=\"quiz admin home\" width=\"1366\" height=\"729\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-300x160.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-1024x546.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-768x410.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-720x384.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-520x278.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/quiz-admin-home-320x171.png 320w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>Navbar.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% load static %}\r\n \r\n&lt;style&gt;\r\n  .greet{\r\n    font-size: 18px;\r\n    color: #fff;\r\n    margin-right: 20px;\r\n  }\r\n&lt;\/style&gt;\r\n \r\n&lt;nav class=\"navbar navbar-expand-lg navbar-dark bg-dark\"&gt;\r\n  &lt;button class=\"navbar-toggler\" type=\"button\" data-toggle=\"collapse\" data-target=\"#navbarNav\" aria-controls=\"navbarNav\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"&gt;\r\n    &lt;span class=\"navbar-toggler-icon\"&gt;&lt;\/span&gt;\r\n  &lt;\/button&gt;\r\n  &lt;div class=\"collapse navbar-collapse\" id=\"navbarNav\"&gt;\r\n \r\n    &lt;ul class=\"navbar-nav\"&gt;\r\n      \r\n      &lt;li class=\"nav-item active\"&gt;\r\n        &lt;a class=\"nav-link\" href=\"{% url 'home' %}\"&gt;Home&lt;\/a&gt;\r\n      &lt;\/li&gt;\r\n      &lt;\/li&gt;\r\n      &lt;li class=\"nav-item active\"&gt;\r\n        \r\n      {% if request.user.is_staff %}\r\n      &lt;\/li&gt;\r\n      &lt;li class=\"nav-item active\"&gt;\r\n        &lt;a class=\"nav-link\" href=\"{% url 'addQuestion' %}\"&gt;Add Question&lt;\/a&gt;\r\n      &lt;\/li&gt;\r\n      {% endif %} \r\n \r\n      &lt;\/li&gt;\r\n      &lt;li class=\"nav-item\"&gt;\r\n        &lt;a class=\"nav-link\" href=\"{% url 'login' %}\"&gt;Login&lt;\/a&gt;\r\n      &lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n \r\n  &lt;span class=\"greet\"&gt;Hello, {{request.user}}&lt;\/span&gt;\r\n  &lt;span &gt;&lt;a  class=\"greet\" href=\"{% url 'logout' %}\"&gt;Logout&lt;\/a&gt;&lt;\/span&gt;\r\n \r\n&lt;\/nav&gt;\r\n<\/pre>\n<h4>AddQuestion.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% extends 'Quiz\/dependencies.html' %}\r\n \r\n{% block content %}\r\n \r\n&lt;div class=\"jumbotron container row\"&gt;\r\n    &lt;div class=\"col-md-6\"&gt;\r\n        &lt;h1&gt;Add Question&lt;\/h1&gt;\r\n        &lt;div class=\"card card-body\"&gt;\r\n           &lt;form action=\"\" method=\"POST\"&gt;\r\n              {% csrf_token %}\r\n                {{form.as_p}}\r\n                &lt;br&gt;\r\n             &lt;input type=\"submit\" name=\"Submit\"&gt;\r\n             &lt;\/form&gt;\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n \r\n&lt;\/div&gt;\r\n \r\n{% endblock %}\r\n \r\n<\/pre>\n<p><strong>Add Question page <\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-96135\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question.png\" alt=\"add quiz question\" width=\"1366\" height=\"729\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-300x160.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-1024x546.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-150x80.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-768x410.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-720x384.png 720w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-520x278.png 520w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/add-quiz-question-320x171.png 320w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<h4>dependencies.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% load static %}\r\n&lt;html&gt;\r\n    &lt;head&gt;\r\n        &lt;title&gt;\r\n            DataFlair Online Quiz with Django\r\n        &lt;\/title&gt;\r\n        &lt;link rel=\"stylesheet\" href=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.5.0\/css\/bootstrap.min.css\" integrity=\"sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk\" crossorigin=\"anonymous\"&gt;\r\n    &lt;\/head&gt;\r\n    &lt;body&gt;        \r\n        {% include 'Quiz\/navbar.html' %}\r\n        {% block content %}   \r\n        {% endblock %}\r\n        &lt;br&gt;\r\n       \r\n        &lt;script src=\"https:\/\/code.jquery.com\/jquery-3.5.1.slim.min.js\" integrity=\"sha384-DfXdz2htPH0lsSSs5nCTpuj\/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj\" crossorigin=\"anonymous\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/cdn.jsdelivr.net\/npm\/popper.js@1.16.0\/dist\/umd\/popper.min.js\" integrity=\"sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo\" crossorigin=\"anonymous\"&gt;&lt;\/script&gt;\r\n    &lt;script src=\"https:\/\/stackpath.bootstrapcdn.com\/bootstrap\/4.5.0\/js\/bootstrap.min.js\" integrity=\"sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh\/kR0JKI\" crossorigin=\"anonymous\"&gt;&lt;\/script&gt;\r\n    &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<h4>Login.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% extends 'Quiz\/dependencies.html' %}\r\n{% load static%}\r\n{% block content %}\r\n&lt;div class=\"container jumbotron\"&gt;\r\n    &lt;form method=\"POST\" action=\"\"&gt;\r\n        {% csrf_token %}\r\n        &lt;p&gt;&lt;input type=\"text\" name=\"username\" placeholder=\"Username...\"&gt;&lt;\/p&gt;\r\n        &lt;p&gt;&lt;input type=\"password\" name=\"password\" placeholder=\"Password...\" &gt;&lt;\/p&gt;\r\n        &lt;input class=\"btn btn-success\" type=\"submit\" value=\"Login\"&gt;\r\n        &lt;p&gt;Do not have an account&lt;a href='{% url 'register' %}'&gt;Register&lt;\/a&gt;&lt;\/p&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/div&gt;\r\n{% endblock %}\r\n<\/pre>\n<h4>Register.html<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">{% extends 'Quiz\/dependencies.html' %}\r\n{% load static %}\r\n{% block content %}\r\n&lt;div class=\"container jumbotron\"&gt;\r\n    &lt;form method=\"POST\" action=\"\" &gt;\r\n        {% csrf_token %}\r\n        {{form.as_p}}\r\n       \r\n        &lt;input class=\"btn btn-success\" type=\"submit\" value=\"Register Account\"&gt;\r\n    &lt;\/form&gt;\r\n&lt;\/div&gt;\r\n{% endblock %}\r\n<\/pre>\n<h3>Summary<\/h3>\n<p>We have developed an Online Quiz application Project using Python Django. We developed quiz web application with following functionalities:\u00a0Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page.\u00a0You can develop more interesting projects with Django, so keep exploring and keep learning.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quiz &#8211; best way to check our knowledge on a particular topic. We have visited a lot of quiz platforms lately, right! Ever wondered if you could develop one. In this article, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":96136,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19149],"tags":[24419,21104,24420],"class_list":["post-96130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-create-python-quiz","tag-django-quiz-app","tag-online-django-quiz"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create a Quiz Web Application with Python Django - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn how to create quiz web application with Python Django with user &amp; admin roles and following functionalities: Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create a Quiz Web Application with Python Django - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn how to create quiz web application with Python Django with user &amp; admin roles and following functionalities: Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-28T04:55:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T08:23:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create a Quiz Web Application with Python Django - DataFlair","description":"Learn how to create quiz web application with Python Django with user & admin roles and following functionalities: Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/","og_locale":"en_US","og_type":"article","og_title":"How to Create a Quiz Web Application with Python Django - DataFlair","og_description":"Learn how to create quiz web application with Python Django with user & admin roles and following functionalities: Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page","og_url":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2021-05-28T04:55:06+00:00","article_modified_time":"2026-06-01T08:23:08+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"How to Create a Quiz Web Application with Python Django","datePublished":"2021-05-28T04:55:06+00:00","dateModified":"2026-06-01T08:23:08+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/"},"wordCount":755,"commentCount":29,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg","keywords":["create python quiz","django quiz app","online django quiz"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/","url":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/","name":"How to Create a Quiz Web Application with Python Django - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg","datePublished":"2021-05-28T04:55:06+00:00","dateModified":"2026-06-01T08:23:08+00:00","description":"Learn how to create quiz web application with Python Django with user & admin roles and following functionalities: Login,\u00a0Sign up,\u00a0Add Question,\u00a0Quiz Page,\u00a0Result Page","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2021\/05\/create-quiz-web-application-python-django.jpg","width":1200,"height":628,"caption":"create quiz web application python django"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/create-quiz-application-python-django\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Django Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/django\/"},{"@type":"ListItem","position":3,"name":"How to Create a Quiz Web Application with Python Django"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=96130"}],"version-history":[{"count":8,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96130\/revisions"}],"predecessor-version":[{"id":148662,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/96130\/revisions\/148662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/96136"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=96130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=96130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=96130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}