We are basically using the add question form in this to create a form object. This method is only for admin, if any user tries to access this method, the user is redirected to the home page. Result.html displays all this information. And then it calculates the percentage score.įinally, it sends all these calculated values along with time elapsed, number of correct answers, number of incorrect answers to result.html. no negative marking) for every incorrect question. 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.įor Quiz Page: It renders all the questions from QuesModel and then it just passes all the questions to home.htmlįor result page: It calculates the score by giving ten marks for every correct question and zero (i.e. 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. Return render(request,'Quiz/login.html',context) User=authenticate(request,username=username,password=password) Return render(request,'Quiz/register.html',context) Return render(request,'Quiz/addQuestion.html',context) Return render(request,'Quiz/home.html',context) Return render(request,'Quiz/result.html',context) Urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)Ĭode: from django.shortcuts import redirect,renderįrom import login,logout,authenticate Path('register/', registerPage,name='register'), Path('logout/', logoutPage,name='logout'), Path('addQuestion/', addQuestion,name='addQuestion'), Add a URL to urlpatterns: path('blog/', include('blog.urls'))įrom import static Import the include() function: from django.urls import include, pathĢ. Add a URL to urlpatterns: path('', Home.as_view(), name='home')ġ. Add an import: from other_app.views import HomeĢ. Add a URL to urlpatterns: path('',, name='home')ġ. Add an import: from my_app import viewsĢ. The `urlpatterns` list routes URLs to views. add url to urlpatterns: path(‘login/’, loginPage,name=’login’),.import view functions: from Quiz.views import *.Therefore, add the following code in settings.py STATIC_URL = '/static/' To use javascript we have to specify the path of static files. To create a staff (admin) user, run the below command py manage.py createsuperuser But we need a superuser to access the admin site. Here, we are registering our model to the admin site, so that we can update or access the database from the admin panel also. To access, update, create or delete entries in the database (to implement CRUD functionality), we need forms.įorm 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. In Django when we use Sqlite3 database, we don’t have to write table definitions we just have to write models and after that, we have to run the following commands Py manage.py makemigrationsįrom import UserCreationFormįrom import User The _str_() method returns a string representation of any object of QuesModel. ans: This indicates which among the four options is the correct ans.op1: As the quiz contains Multiple choice questions.question: This stores the question, we have also defined maximum length of the question i.e.We just need one model for this project, QuesModel. Op4 = models.CharField(max_length=200,null=True)Īns = models.CharField(max_length=200,null=True) Op3 = models.CharField(max_length=200,null=True) Op2 = models.CharField(max_length=200,null=True) Op1 = models.CharField(max_length=200,null=True) Question = models.CharField(max_length=200,null=True) Starting project:Ĭommands to start the project and app: django-admin startproject DjangoQuizĭjango-admin startapp Quiz 2. Please download the source code of quiz web application: Quiz Web Application Python Code To install Django: pip install Django Download Quiz App Python Code You should have a basic knowledge of the following technologies: Result page (with score, time taken, percentage score, total questions, correct answers, wrong answers).Let’s see what all functionalities we will be developing in this project (for two roles – user and admin): In this article, we will guide you to develop a quiz application using Python Django. We have visited a lot of quiz platforms lately, right! Ever wondered if you could develop one. Quiz – best way to check our knowledge on a particular topic. Free Python course with 35 real-time projects Start Now!!
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |