INDEX
1] PROJECT BASIC QUESTIONS
2] UML
3] TEMPLATE TAGS
4]AUTHENTICATION
5]URLS
6]VIEWS
7]SESSIONS
8]MODELS
9]PROJECT STRUCTURE
VIVA QS
PROJECT BASIC QUESTIONS
1] Explain about your project
Solasta Food Ordering System is an online platform designed to streamline
the food ordering process in hotels.
2] What is the main goal of your project
A] The main goal of SOlasta is to reduce waiting time for customers by
allowing them to browse a digital menu, place their orders, and pay online
using PayPal ,all before arriving at the hotel or while seated.
3]. What is new in your project?
"SOlasta is new because it’s a simple system made for hotels to cut waiting
time. It lets guests order and pay online with PayPal, sending orders
straight to the kitchen—no staff delays."
4. What languages, tools, and technologies are you using in your
project, and why you chose them?
"I used:
Python & Django: Easy to code and has built-in tools for fast
development.
SQLite: Lightweight database, good for a small project.
HTML, CSS, JavaScript: For a basic, interactive web interface.
I chose them because they’re simple, work well together, and fit my
project timeline."
5. Have you studied problems and weaknesses in same existing
systems in the market?
"Yes, I noticed:
Many apps are too complex or focus on delivery, not in-hotel use.
Some still need waiters, slowing things down.
SOlasta fixes this with a direct, simple order-to-kitchen system."
6. What are functional and non-functional requirements? Give
examples.
Functional: What the system does.
o Example: "Users can add food to a cart."
Non-Functional: How it performs.
o Example: "Payment must finish in 5 seconds."
7. What are, and any example of, the following non-functional
requirements?
Performance: Speed of the system.
o Example: "Menu loads in 2 seconds with SQLite."
Scalability: Handling more users.
o Example: "Supports 50 orders at once."
Security: Keeping data safe.
o Example: "PayPal payments are encrypted."
Usability: Easy to use.
o Example: "Clear buttons with CSS styling."
Reliability: Works without fail.
o Example: "95% of orders process correctly."
8. Which software process model are you using in your project and
why?
I followed Agile model in my project because I developed my system
module-wise. First, I worked on the login and registration part, then I
developed the menu display and order checkout system . After that, I
added the payment feature using PayPal. I took feedback from my guide
after every stage and made changes
9.How did you test your system ?
I tested my project using Manual testing . I checked every module like
registration, login, menu display, order placing, and payment process. I
used JavaScript console log to check errors on the client side and used
Django shell to verify database records on the server side. I also tested
form validations, error messages, and page navigation manually.
Debugging Tools Used: JavaScript Console Log, Django Shell, Error
Messages
Since I used a manual form in my project, I included CSRF protection using
{% csrf_token %} in my manual html form templates. This helps to protect
my application from Cross Site Request Forgery attacks by ensuring that
the form is submitted from my own site only.
10. What are some risks you have identified in your project ?
Yes, I have identified some possible risks in my project. The risks are —
payment failure due to poor internet, server crash due to high traffic, data
security risks, wrong order placement by the user, and internet connectivity
problems
11. What is the purpose of integrating PayPal in the system?
"The purpose of integrating PayPal in my system is to provide a safe and
easy online payment method for customers. It helps users to pay their bill
online after ordering food, so they don’t need to wait in line at the hotel for
payment."
12. How does your system ensure data security during payment
processing?
"For data security, I used PayPal payment gateway because PayPal
provides a secure platform for transactions. The user is redirected to the
PayPal website for payment, so sensitive data like card details or bank
details are not stored in my system. This ensures safe and secure payment
processing."
13. Can you explain how you designed the Entity-Relationship (ER)
Diagram for this system?
"I designed the ER Diagram based on the main entities in the system. The
important entities are:
User (Customer)
Menu (Food Items)
Orders
Payment
Admin
The relationships are:
A User can place many Orders.
Each Order contains multiple Menu items.
Every Order has one Payment."
14. What challenges did you face during backend development, and
how did you solve them?
I faced some challenges like:
PayPal payment integration was new to me, so I followed
documentation and online tutorials to implement it.
Handling session management in Django was tricky, but I used
Django’s built-in authentication system for that.
I got some database errors while saving orders, so I used Django
shell to debug and verify data."
15] How does your system reduce waiting time in a hotel
environment?
My system reduces waiting time by allowing customers to order food online
from their phone and pay directly using PayPal. This avoids standing in
queue for ordering or billing. Customers can directly receive their food after
making the online payment, which saves time for both customers and hotel
staff.
16. What is the advantage of online food ordering?
"Online food ordering saves time, avoids waiting in the queue, provides
easy payment options, and improves customer convenience."
17. Which database did you use? Why?
"I used SQLite because it is lightweight, easy to use, and comes pre-
installed with Django framework."
18. Did you use any validation in your project?
Yes, I used form validations for user input like username, email, password,
and payment details to avoid incorrect data."
19. What is the flow of your project?
First, users register or log in, then they browse the food menu, add items to
cart, proceed to checkout, make payment using PayPal, and then receive
order confirmation
20. What are the future enhancements for your project?
In the future, I would like to add features like Google Pay/PhonePe
payments, real-time order tracking, user feedback system, and mobile app
version.
21. What is the role of the admin in your project?
The admin can manage the food menu, update items, view orders placed
by customers, and check payment status
22. What type of users can access your system?
There are two types of users —
1. Customers (who order food)
2. Admin (who manages menu and orders)
23 Advantages of My Project
Saves time for customers by avoiding waiting in queue.
1. Easy online ordering from mobile or laptop.
2. Secure payment using PayPal.
3. User-friendly interface.
4. Reduces workload for hotel staff.
5. Customers can order anytime from anywhere.
6. Admin can easily manage menu and orders.
24 Disadvantages of My Project
1. Internet connection is required to use the system.
2. Payment is limited to PayPal only (other payment methods not
added).
3. No real-time order tracking feature.
4. Suitable for small and medium hotels — needs more features for big
restaurants.
5. If the server crashes or goes down, the system will not work.
UML QUESTIONS
Use case diagram questions
1. What is a use case diagram?
A use case diagram is a visual representation that shows how users
(actors) interact with the system. It helps us understand system
functionality from the user’s perspective.
2. Why did you include use case diagrams in your project?
Use case diagrams help us and stakeholders understand what features the
system offers and how different users like Admin or Customers interact with
those features. It also helps plan the development process.
3. Who are the actors in your system’s use case diagram?
The main actors are:
Customer – who places orders
Admin – who manages the system
There could be more actors like delivery staff or restaurant manager if
needed.
4. What are the main use cases for the Admin?
Admin can:
1. View dashboard
2. Manage registered users
3. Manage food menu (add, update, delete items)
4. Handle order management
5. Generate invoices
6. Update order status
5. Explain the Admin's Dashboard use case.
The dashboard gives the Admin a complete overview of the system, like
order status, number of users, system analytics, and ongoing activities.
6. How does the Admin manage registered users?
The Admin can view all users, update their details, deactivate or remove
accounts if needed, and ensure only valid users are active.
7. Can you explain the use case 'Manage Food Menu'?
This use case allows the Admin to add new food items, update prices or
descriptions, and delete items that are not available.
8. What is included in the Order Management use case?
It includes tracking food orders, updating their status, solving payment or
delivery issues, and canceling orders if needed.
9. What does the Invoice Generation use case do?
After an order is placed, the system creates an invoice. It includes food
item costs, taxes, total amount, and payment status.
10. What is the benefit of creating these use case diagrams?
It helps us plan and develop the system better. It shows who does what
and ensures no feature is missed. It also helps in future updates or
changes.
USER USE CASE DIAGRAM
1. Who is the primary actor in the User Use Case Diagram?
The primary actor is the User who interacts with the system to place food
orders, make payments, and manage their account.
2. How many main use cases are there for the User?
There are five main use cases for the User:
1. Sign Up
2. Sign In
3. Place Order
4. Cart Editing
5. Make Payment
3. What happens in the Signup use case?
In the Signup use case, a new user registers by entering details like name,
email, phone number, and password. After registration, they can use the
platform.
4. What is the Sign In use case?
The Sign In use case allows existing users to log in to their account using
their email or username and password.
5. What happens in the Place Order use case?
After signing in, users can browse the menu, select food items, and place
an order. The order is then sent to the restaurant for preparation.
6. Explain the Cart Editing use case.
In the Cart Editing use case, the user can add, remove, or change the
quantity of items in their cart before making the final payment.
7. What is the purpose of the Make Payment use case?
This use case allows the user to complete their order by making payment
through options like credit/debit cards, online wallets, or cash on delivery.
8. Why is the Cart Editing use case important?
It gives flexibility to the user to review and update their order before
payment, ensuring accuracy and customer satisfaction.
9. What happens after the user makes the payment?
After successful payment, the order is confirmed and processed for delivery
or pickup.
10. What is the main benefit of using the User Use Case Diagram?
It helps to understand the user journey and their interaction with the
system, making development and user experience better.
ARCHITECTURAL DESIGN VIVA QUESTIONS
1. What is Architectural Design in Software Engineering?
Architectural design defines the structure, organization, and interaction of
different parts of a system. It provides a high-level framework for building
software efficiently.
2. What type of architecture is used in the Food Ordering System?
The Food Ordering System uses Three-Tier Architecture.
3. What are the three layers of Three-Tier Architecture?
The three layers are:
1. Client Layer (Presentation Layer)
2. Business Layer (Application Layer)
3. Data Layer (Database Layer)
4. What is the role of the Client Layer?
The Client Layer provides the user interface where users can interact with
the system — like signing up, logging in, browsing menu, and making
payments.
5. What is the role of the Business Layer?
The Business Layer handles the business logic like processing user
requests, validating input, managing orders, and connecting the user
interface with the database.
6. What is the function of the Data Layer?
The Data Layer manages the database. It stores and retrieves user details,
menu items, order records, and payment information.
7. What are the advantages of using Three-Tier Architecture?
Advantages include:
Modularity & Maintainability
Faster Communication
Improved Performance & Scalability
8. Why is Modularity important in Three-Tier Architecture?
Modularity allows developers to update or modify one layer (like UI or
database) without affecting the other layers.
9. How does the Business Layer improve performance?
It processes and validates user requests efficiently before sending them to
the database, reducing system load.
10. Which databases can be used in the Data Layer?
Databases like MySQL, MongoDB, or any other relational or non-relational
database can be used.
11. How does Three-Tier Architecture support Scalability?
The system can handle more users and orders by upgrading layers
independently without disturbing the whole system.
CONNECTIVITY AND CARDINALITY QUESTIONS
1. What is Connectivity and Cardinality in a Database?
Connectivity and Cardinality define the relationships between different
entities (tables) in a database and how data in one table relates to data in
another.
2. What are the types of Relationships in a Database?
There are three types of relationships:
1. One-to-One (1:1)
2. One-to-Many (1:N)
3. Many-to-Many (M:N)
3. What is a One-to-One (1:1) Relationship?
In this relationship, one record in a table is linked with only one record in
another table.
4. Give examples of One-to-One Relationship in the Food Ordering
System.
Examples:
Each registered user has a unique account profile.
Each restaurant has a single administrator.
5. What is a One-to-Many (1:N) Relationship?
In this relationship, one record in Table A is linked to multiple records in
Table B, but records in Table B link back to only one record in Table A.
6. Give examples of One-to-Many Relationship in the Food Ordering
System.
Examples:
One customer can place many orders.
One restaurant can have many food items.
7. What is a Many-to-Many (M:N) Relationship?
In this relationship, multiple records in Table A can relate to multiple records
in Table B.
8. Give examples of Many-to-Many Relationship in the Food Ordering
System.
Example:
Customers can order multiple food items, and the same food item can
be ordered by many customers.
9. What is the purpose of a Junction Table in Many-to-Many
Relationship?
A junction table is used to connect two tables in a Many-to-Many
relationship and store their association data.
10. Why is it important to understand Connectivity and Cardinality in
Database Design?
It helps in designing an efficient database structure that maintains data
consistency, reduces redundancy, and improves performance.
11. How does One-to-Many Relationship help in the Food Ordering
System?
It helps manage data like customers placing multiple orders or restaurants
having multiple menu items in an organized way.
DFD QUESTIONS
1. What is a Data Flow Diagram (DFD)?
A DFD is a graphical tool used to show how data moves within a system —
from input to processing to storage and output.
2. What is the main purpose of a DFD?
The main purpose of a DFD is to visualize the flow of data, understand the
system’s process, and identify how data is transferred between different
parts of the system.
3. What are the advantages of using a DFD?
Advantages are:
Easy to understand data flow
Identifies system boundaries
Simplifies complex processes
Helps communication between developers and users
4. What are the different levels of a DFD?
The levels of a DFD are:
1. Level 0 – Context Diagram
2. Level 1 – High-Level Process Breakdown
3. Level 2 or more – Detailed Sub-Processes
5. What is a Context Level DFD (Level 0)?
It shows the entire system as a single process with its interaction with
external entities (users or other systems).
6. What does Level 1 DFD represent?
Level 1 DFD breaks the single process from the Context Diagram into
multiple major processes to show detailed data flow.
7. What is shown in Level 2 DFD?
Level 2 DFD shows sub-processes of Level 1 processes in more detail and
explains internal data flow.
8. What are External Entities in a DFD?
External Entities are users, systems, or devices that interact with the
system but are outside the system boundary.
9. What is a Data Store in a DFD?
A Data Store is a storage place where data is temporarily or permanently
saved, such as a database.
10. Why is DFD important in System Design?
DFD helps in system analysis, identifies inefficiencies, clarifies
requirements, and improves system design by visualizing data movement.
11. Can you give an example of an External Entity in the Food
Ordering System?
Example: Customer or Restaurant Manager is an external entity who
interacts with the system.
12. What is shown by Arrows in DFD?
Arrows represent the flow of data between processes, data stores, and
external entities.
What are the basic components of a DFD?
The basic components of a DFD are:
External Entities
Processes
Data Stores
Data Flows (Arrows)
14. What is a Process in a DFD?
A Process in DFD shows how data is processed, transformed, or managed
within the system.
15. How is data flow represented in a DFD?
Data flow is represented by arrows showing the movement of data between
entities, processes, and data stores.
16. What is the difference between Level 0 and Level 1 DFD?
Level 0 shows the overall system as a single process.
Level 1 breaks that process into sub-processes for more detailed
understanding.
17. What is the significance of DFD in database design?
DFD helps identify data input, processing, and storage requirements —
which helps in designing database tables and relationships.
18. What are the symbols used in DFD?
The common symbols are:
Rectangle → External Entity
Circle/Oval → Process
Open-ended Rectangle → Data Store
Arrow → Data Flow
19. What is the role of Data Store in DFD?
Data Stores are used to store information like Customer Details, Order
Details, Payment Info in the Food Ordering System.
20. How does DFD help developers?
DFD helps developers understand the system flow, avoid mistakes, and
develop an efficient system by visualizing how data moves.
21. What is the importance of DFD in the Food Ordering System?
In the Food Ordering System, DFD helps show:
How customers place orders
How orders are processed
How data is stored in the database
How reports are generated
22. What happens in Level 2 DFD of Food Ordering System?
In Level 2 DFD, each Level 1 process like “Order Processing” or “Payment
Handling” is further divided into smaller tasks for detailed design.
23. What is the use of DFD in Real-Life Projects?
DFD is used to design applications like:
Online Shopping
Food Delivery
Banking Systems
Library Management Systems
24. What is the difference between DFD and Flowchart?
Flowchart shows control flow (decision making, loops) while DFD shows
data flow between processes.
25. How does DFD help stakeholders?
DFD helps stakeholders (clients, developers, testers) to understand the
system flow easily without technical coding knowledge.
ER DIAGRAM
What is an ER Diagram?
An ER Diagram is a visual representation of entities, attributes, and
relationships in a database system.
2. Why is ER Diagram important in database design?
It helps to structure data properly, avoid redundancy, maintain data
integrity, and support efficient data retrieval.
3. What are the main components of an ER Diagram?
The main components are:
Entities
Attributes
Relationships
4. What is an Entity?
An entity is a real-world object or concept that can store data. Example:
Customer, Order, Payment.
5. What are Attributes in ER Diagram?
Attributes are the properties or characteristics of an entity.
Example: Customer Name, Order Date, Payment Status.
6. What is a Primary Key?
Primary Key is a unique attribute that identifies each record in an entity.
Example: Customer_ID, Order_ID.
7. What are the key entities in the Food Ordering System ER Diagram?
The key entities are:
Customer
Food Menu
Order
Restaurant Staff
Payment
8. What type of relationship exists between Customer and Order?
One-to-Many (1:N) — One customer can place multiple orders.
9. How is the Food Menu entity connected in the ER Diagram?
Food Menu is related to Order, where one order can have multiple food
items.
10. What is the relationship between Order and Payment?
One-to-One (1:1) — Each order has one payment transaction linked to it.
11. Why is ER Diagram useful in the Food Ordering System?
It helps in:
Organizing data properly
Avoiding data duplication
Easy retrieval of information
Future enhancement of the system
12. What is Cardinality in ER Diagram?
Cardinality defines the number of occurrences of one entity that can be
related to another entity. Example: 1:1, 1:N, M:N.
13. What is the role of Restaurant Staff entity?
Restaurant Staff handles order preparation, processing, and updating order
status.
14. Can Feedback be included in the ER Diagram?
Yes, Feedback entity can be connected to Customer and Order entities for
rating or review purposes.
15. How does ER Diagram help in future system development?
ER Diagram helps in:
Adding new features like discounts or offers
Expanding the database easily
Maintaining performance and data accuracy Customers entity?
The Customers entity stores unique information of users like name, contact
details, address, and login credentials.
food_orders entity store?
The food_orders entity stores order details like Order ID, Customer ID,
Order Date, Total Amount, and Order Status.
order_items entity?
The order_items entity lists all the food items included in each order. It acts
as a link between food_orders and Food Menu entities.
payments entity?
The payments entity stores payment transaction details like Payment ID,
Payment Method, Payment Status, and Order ID.
cart entity?
The cart entity manages the items added by customers before placing an
order. It temporarily stores selected food items.
relationships ?
One-to-Many (1:N) — A single customer can place multiple food orders.
One-to-Many (1:N) — One order can have multiple items listed in
order_items.
One-to-One (1:1) — Each order has one corresponding payment
transaction.
One-to-One (1:1) — Each customer has a separate cart to add items
before placing an order.
order_items is used to handle Many-to-Many (M:N) relationships between
food_orders and Food Menu because one order can have multiple items,
and one item can be part of multiple orders
SEQUENCE DIAGRAM QUESTIONS
1. What is a Sequence Diagram?
A Sequence Diagram is a UML diagram that shows how objects in a
system interact with each other in a sequence over time through message
passing.
2. What is the main purpose of using a Sequence Diagram?
The main purpose is to model the flow of control and interactions between
different system components, showing the order of messages exchanged.
3. What are the main components used in a Sequence Diagram?
The key components are:
Actors (like Customer)
Objects (like Cart, Food Menu, Order, Payment Gateway, Payments)
Messages (communication between actors and objects)
Lifelines (vertical dotted lines representing object existence)
Activation Bars (thin rectangles showing object activity)
4. Who are the actors in the Food Ordering System Sequence
Diagram?
The main actor is the Customer who interacts with the system.
5. Name the objects involved in the Sequence Diagram of the Food
Ordering System.
The objects are:
Food Menu
Cart
Orders
Payment Gateway
Payments
6. What is the first interaction in the Sequence Diagram of a Food
Ordering System?
The first interaction is when the Customer selects items from the Food
Menu and adds them to the Cart.
7. What happens after the customer adds items to the cart?
The customer can either:
Remove items
Proceed to checkout
Once checkout is initiated, the Cart sends a request to create an
Order.
8. How is the payment process handled in the Sequence Diagram?
The Order is sent to the Payment Gateway for processing. If the payment is
successful, the Order is confirmed. If payment fails, the customer is notified
to retry.
9. What happens after a successful payment?
After successful payment, the system records the transaction in Payments
and sends the order details to the restaurant/kitchen for preparation.
10. What happens if the payment fails?
If the payment fails, the system sends a failure notification to the Customer,
asking them to retry or use another payment method.
11. What is the role of the Cart in the Sequence Diagram?
The Cart stores selected items by the customer before checkout. It can
update, add, or remove items and helps in order creation.
12. Why are Sequence Diagrams important in system design?
Sequence Diagrams help in understanding:
The flow of control
Communication between system parts
Error handling
Order of operations
They improve clarity and help developers in implementation.
DATA BASE DESIGN
1. What is a Database Management System (DBMS)?
A DBMS is software that helps in storing, managing, and retrieving data
efficiently and securely in an organized manner.
2. Why is DBMS important in a Food Ordering System?
DBMS is important because it stores customer details, order details,
payment records, menu items, and helps in retrieving this data quickly for
smooth operations.
3. What are the main objectives of database design?
The main objectives are:
Efficient Data Storage
Data Integrity & Consistency
Fast & Reliable Data Retrieval
Scalability
Security
4. What is Normalization?
Normalization is the process of organizing data into multiple related tables
to reduce redundancy, avoid anomalies, and maintain data integrity.
5. What are the advantages of Normalization?
Advantages include:
Minimized duplicate data
Avoidance of update anomalies
Ensures data integrity
Efficient data storage
6. What are Primary Key (PK) and Foreign Key (FK)?
Primary Key (PK): A unique identifier for a record in a table.
Foreign Key (FK): A field in a table that refers to the primary key of
another table to create a relationship between them.
7. Mention some important tables used in Food Ordering System
Database.
Tables include:
Users
Orders
Menu Items
Categories
Payments
Cart
8. What is the role of the 'Orders' table?
It stores details about placed orders such as Order ID, Customer ID, Date,
Total Amount, etc.
9. Why was SQLite chosen for the Food Ordering System?
SQLite was chosen because:
It is lightweight and easy to use
No separate server is required
Suitable for small applications
High performance for read-heavy operations
10. What is the difference between SQLite and MySQL?
SQLite MySQL
Server-less Requires Server
Lightweight Heavyweight
Easy setup Complex setup
Suitable for small apps Suitable for large apps
11. What is Data Integrity?
Data Integrity means maintaining accuracy, correctness, and consistency of
data stored in the database.
12. What do you mean by Scalability in Database Design?
Scalability means the ability of the database to handle increased data and
users in the future without major changes in structure.
Tables
1. What is the purpose of the Customer Table?
The Customer Table stores user details like:
Username
Email
Password
Role (Customer/Admin)
It helps in user authentication and authorization.
2. What is stored in the FoodMenu Table?
The FoodMenu Table stores:
Food Item Name
Food Category (like Starter, Main Course, Dessert)
Price of each item
This table helps display the menu to customers.
3. What details are stored in the Orders Table?
The Orders Table stores:
Order ID
Customer ID
Order Status (Placed, Preparing, Delivered, Cancelled)
Order Date and Time (Timestamps)
4. What is the purpose of the Cart Table?
The Cart Table holds items that the customer adds before placing the final
order.
It stores:
Customer ID
Food Item ID
Quantity of items
This data is temporary until checkout.
5. What information does the Payments Table contain?
The Payments Table stores:
Payment ID
Order ID
Payment Amount
Payment Method (Cash, Card, UPI)
Payment Timestamp
6. Which table stores temporary data before placing an order?
The Cart Table stores temporary data until the customer proceeds for
checkout.
7. What is the relationship between Orders Table and Payments
Table?
The Orders Table is connected to the Payments Table using a Foreign Key
(Order ID).
Every payment is linked to a specific order.
8. Why do we need a FoodMenu Table?
The FoodMenu Table allows dynamic management of food items like
adding, updating, or deleting items from the menu.
9. Which table contains the role of the user?
The Customer Table contains the role (Customer or Admin) for access
control and system security.
10. What happens to Cart Table data after placing the order?
Once the order is placed:
Data from the Cart Table moves to the Orders Table.
The Cart Table gets emptied for that customer.
Questions on Django Template Tags & Template Inheritance
1. What are Django Template Tags?
Answer:
Template tags in Django are special commands written inside {% %}
which help to add dynamic logic like conditions, loops, and variables
inside HTML files.
2. What is the use of {% if %} tag in Django?
Answer:
It is used to check conditions in templates. If the condition is True, it
will display the content. Otherwise, it can show alternative content
using {% else %}.
3. How do you display a list of items in Django Template?
Answer:
By using {% for %} loop tag. Example:
django
CopyEdit
{% for item in products %}
{{ item.name }}
{% endfor %}
4. What is {% include %} tag?
Answer:
It is used to include another HTML file (like header.html or footer.html)
inside the main template to avoid repeating code.
Example:
django
CopyEdit
{% include 'header.html' %}
5. Why do we use {% url %} tag?
Answer:
To create dynamic URLs in templates based on the Django URL
names.
Example:
django
CopyEdit
<a href="{% url 'home' %}">Home</a>
6. What is the use of {% load static %}?
Answer:
It is used to load static files like CSS, JavaScript, and images in
Django templates.
Example:
django
CopyEdit
{% load static %}
<img src="{% static 'images/logo.png' %}">
7. What is {% with %} tag used for?
Answer:
It is used to create a temporary variable inside a template.
{% with total=product.price|add:tax %}
{{ total }}
{% endwith %}
Template Inheritance Questions:
8. What is Template Inheritance in Django?
Answer:
Template inheritance is a feature in Django where we create a base
template with common code (like header, footer) and extend it in child
templates using {% extends 'base.html' %}. It helps in reusing code.
9. What is {% block content %} used for?
Answer:
It defines a block of code in the base template which can be replaced
or filled by child templates.
Example in base.html:
{% block content %}{% endblock %}
10. How do you inherit a template in Django?
Answer:
We use {% extends 'base.html' %} at the top of the child template to
inherit the parent template.
11. Why is Template Inheritance important in Django projects?
Answer:
Avoids code duplication
Easy to manage layouts
Better structure
Reusability of header, footer, navbar, etc.
12. Can we have multiple {% block %} tags in a base template?
Answer:
Yes, we can have multiple blocks like {% block content %}, {% block
title %}, {% block sidebar %} etc., and they can be overridden in child
templates.
13. What happens if we don’t use {% endblock %} in templates?
Answer:
It will show a template syntax error because every {% block %} must
be closed with {% endblock %}.
What Are Django Templates?
Django templates are HTML files with special syntax that allow you to insert
dynamic content. They’re processed by Django’s templating engine to
generate the final HTML sent to the user’s browser. The two main syntax
elements are:
{{ variable }}: Outputs the value of a variable.
{% tag %}: Executes logic (like loops or conditionals).
What Does {{ }} Do?
The double curly braces {{ }} tell Django to evaluate and display the value
of whatever’s inside them. Think of it as a placeholder: when the template
is rendered, Django replaces {{ variable }} with the actual data assigned to
variable.
For example:
If variable = "Hello", then {{ variable }} becomes Hello in the HTML
output.
It’s not just for simple strings—it can handle numbers, lists, objects,
or even the result of a method call.
Where Do Variables Like cat.category_title Come From?
Variables in {{ }} don’t just appear magically—they’re passed from your
Django view to the template. A view is a Python function (or class) that
handles a request, does some logic (like fetching data from a database),
and returns a response. When rendering a template, the view provides a
context—a dictionary of data that the template can access.
AUTHENTICATION IN DJANGO --- RELATED QUESTIONS
1. How does Django handle user authentication?
Django handles user authentication through its django.contrib.auth module,
which provides tools for:
User Authentication: It validates user credentials (username and
password) via authenticate() and login() functions.
User Sessions: It uses session-based authentication, storing user
login details in a secure cookie (django.contrib.sessions).
User Authorization: It checks user permissions and groups for
access control using the user.has_perm(), user.is_staff, and
user.is_superuser.
Login/Logout: It provides views like LoginView and LogoutView for
handling user login/logout actions.
Password Management: It includes features like password hashing,
reset, and change functionality
Authentication in Django: Key Concepts
Django provides a built-in authentication system (django.contrib.auth) that
handles user accounts, login/logout, permissions, and groups. Before
diving into questions and tests, here’s a quick overview:
User Model: Represents users (can be customized).
Authentication Views: Built-in views like LoginView and LogoutView.
Middleware: AuthenticationMiddleware associates users with
requests via sessions.
Decorators: Like @login_required to restrict access.
Testing: Django’s TestCase and Client help simulate user
interactions.
AUTHENTICATION BRIEF SUMMARY
Authentication is a built-in system in Django that manages:
User Login
User Registration
Logout
Password Management
Permission Handling
User Sessions
Main Components of Django Authentication:
1. User Model
Provided by:
from django.contrib.auth.models import User
This model stores user details like:
username
password (encrypted)
email
first_name
last_name
is_staff (for admin panel access)
is_superuser (full access)
2. Authentication Views
Django provides ready-made views for handling authentication:
View Name Purpose
LoginView For user login
LogoutView For user logout
PasswordChangeView To change password
PasswordResetView To reset password by email
Example:
from django.contrib.auth.views import LoginView, LogoutView
3. Authentication Middleware
Located in:
'django.contrib.auth.middleware.AuthenticationMiddleware'
This middleware connects the logged-in user to every request using
sessions.
We can access the logged-in user in views using:
request.user
4. Authentication Decorators
Django provides decorators to protect views.
Example:
from django.contrib.auth.decorators import login_required
@login_required
def profile(request):
return render(request, 'profile.html')
This ensures only logged-in users can access this page.
5. Groups and Permissions
Used for role-based access control.
from django.contrib.auth.models import Group, Permission
We can assign users to groups and give different permissions.
Example:
Admin can add/delete products.
Customers can only view products.
6. CSRF Protection in Django
CSRF = Cross Site Request Forgery
→ It is a security feature to protect forms from external attacks.
Enabled by default in Django using:
{% csrf_token %}
Middleware used:
'django.middleware.csrf.CsrfViewMiddleware'
Without CSRF token, Django will block POST requests.
Authentication Flow in Django:
1. User fills login form.
2. Django checks credentials from the database.
3. If correct → Creates a session.
4. User stays logged in until logout.
5. CSRF token protects all sensitive forms (like Login, Registration,
Payment).
Viva Questions and Answers on Authentication in Django
1. What is authentication in Django?
Answer: Authentication in Django is the process of verifying a user’s
identity (e.g., via username and password). It determines who a user
is. Django’s built-in system (django.contrib.auth) handles this,
including user login, logout, and session management. It’s distinct
from authorization, which controls what a user can do.
2. How does Django’s authentication system work?
Answer: Django’s authentication system uses:
o The User model to store user data (username, password,
email, etc.).
o Session-based authentication, where a user logs in, and a
session ID is stored in a cookie.
o AuthenticationMiddleware to link the session to a request.user
object.
o Built-in views like LoginView and functions like authenticate()
and login() to verify credentials and start a session.
3. What is the difference between authentication and authorization in
Django?
Answer:
o Authentication: Verifies a user’s identity (e.g., "Is this really
John?").
o Authorization: Determines what an authenticated user can do
(e.g., "Can John delete posts?"). In Django, authorization is
managed via permissions and groups.
4. How do you set up authentication in a Django project?
Answer:
1. Ensure 'django.contrib.auth' is in INSTALLED_APPS (it’s there
by default).
2. Add authentication URLs in urls.py:
python
CollapseWrapCopy
from django.contrib.auth import views as auth_views
urlpatterns = [
path('login/', auth_views.LoginView.as_view(), name='login'),
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
]
3. Create a login template (e.g., login.html) with a form.
4. Use @login_required to protect views.
5. What is the purpose of the @login_required decorator?
Answer: The @login_required decorator restricts access to a view,
redirecting unauthenticated users to the login page. Example:
python
CollapseWrapCopy
from django.contrib.auth.decorators import login_required
@login_required
def my_view(request):
return HttpResponse("You’re logged in!")
If the user isn’t logged in, they’re redirected to the URL defined by
LOGIN_URL (default: /accounts/login/).
6. How do you create a custom user model in Django?
Answer: To customize the User model:
1. Create a new model inheriting from AbstractUser or
AbstractBaseUser.
2. Update settings.py with AUTH_USER_MODEL =
'myapp.MyUser'. Example:
# models.py
from django.contrib.auth.models import AbstractUser
class MyUser(AbstractUser):
phone_number = models.CharField(max_length=15)
3. Run migrations (makemigrations and migrate).
7. What is the authenticate() function in Django?
Answer: The authenticate() function checks a user’s credentials
(e.g., username and password) against the database. It returns a
User object if valid, or None if invalid. Example:
from django.contrib.auth import authenticate
user = authenticate(username='john', password='secret')
if user:
print("Valid user!")
8. How do you log a user in and out programmatically?
Answer:
o Login: Use login() after authentication.
from django.contrib.auth import authenticate, login
user = authenticate(request, username='john', password='secret')
if user:
login(request, user)
o Logout: Use logout().
from django.contrib.auth import logout
logout(request)
9. What is the role of CSRF_TOKEN in authentication forms?
Answer: The {% csrf_token %} in templates generates a hidden input
with a token to protect against Cross-Site Request Forgery (CSRF)
attacks. It ensures that POST requests (like login forms) come from
your site, not a malicious source.
10. How do you test authentication in Django?
Answer: Use Django’s TestCase and Client:
1. Create a test user.
2. Simulate login with client.login().
3. Test protected views. Example in tests.py:
from django.test import TestCase, Client
from django.contrib.auth.models import User
class AuthTest(TestCase):
def setUp(self):
self.client = Client()
self.user = User.objects.create_user(username='testuser',
password='12345')
def test_login(self):
self.client.login(username='testuser', password='12345')
response = self.client.get('/protected-view/')
self.assertEqual(response.status_code, 200)
11. How does Django store passwords?
Answer: Django hashes passwords using a strong algorithm (default:
PBKDF2 with SHA256). The User model’s password field stores the
hashed value, not plaintext, ensuring security.
12. What is session-based authentication in Django?
Answer: After a user logs in, Django creates a session ID stored in a
cookie. The SessionMiddleware and AuthenticationMiddleware this ID
to associate request.user with the authenticated user across
requests.
13 What is CSRF?
CSRF stands for Cross-Site Request Forgery.
It is an attack where unauthorized commands are transmitted from a
trusted user.
14. How does Django prevent CSRF attacks?
Django provides built-in CSRF protection middleware which checks for
CSRF tokens in POST requests.
15. What is {% csrf_token %} in Django?
It generates a unique token for each user session to prevent CSRF attacks.
It is used in HTML forms:
AUTHENTICATION BRIEF SUMMARY
Authentication is a built-in system in Django that manages:
User Login
User Registration
Logout
Password Management
Permission Handling
User Sessions
Main Components of Django Authentication:
1. User Model
Provided by:
python
CopyEdit
from django.contrib.auth.models import User
This model stores user details like:
username
password (encrypted)
email
first_name
last_name
is_staff (for admin panel access)
is_superuser (full access)
2. Authentication Views
Django provides ready-made views for handling authentication:
View Name Purpose
LoginView For user login
LogoutView For user logout
PasswordChangeView To change password
PasswordResetView To reset password by email
Example:
python
CopyEdit
from django.contrib.auth.views import LoginView, LogoutView
3. Authentication Middleware
Located in:
python
CopyEdit
'django.contrib.auth.middleware.AuthenticationMiddleware'
This middleware connects the logged-in user to every request using
sessions.
We can access the logged-in user in views using:
python
CopyEdit
request.user
4. Authentication Decorators
Django provides decorators to protect views.
Example:
from django.contrib.auth.decorators import login_required
@login_required
def profile(request):
return render(request, 'profile.html')
This ensures only logged-in users can access this page.
5. Groups and Permissions
Used for role-based access control.
from django.contrib.auth.models import Group, Permission
We can assign users to groups and give different permissions.
Example:
Admin can add/delete products.
Customers can only view products.
6. CSRF Protection in Django
CSRF = Cross Site Request Forgery
→ It is a security feature to protect forms from external attacks.
Enabled by default in Django using:
{% csrf_token %}
Middleware used:
'django.middleware.csrf.CsrfViewMiddleware'
Without CSRF token, Django will block POST requests.
Authentication Flow in Django:
6. User fills login form.
7. Django checks credentials from the database.
8. If correct → Creates a session.
9. User stays logged in until logout.
10. CSRF token protects all sensitive forms (like Login,
Registration, Payment).
Django URLs Viva Questions:
1. What is urls.py in Django?
It is used to map URLs (web addresses) to views (functions or classes) in
Django. It controls how the website responds to user requests.
2. What is the use of path() in urls.py?
The path() function is used to define URL patterns. It takes the URL string
and the view function to be called.
3. What is include() in Django URLs?
include() is used to include another URL configuration from a different app.
It helps in organizing URLs for large projects.
4. What is name parameter in URLs?
name is used to give a unique name to a URL pattern. It helps in reverse
URL mapping and using {% url 'name' %} in templates.
5. How did you design URLs in your project?
I created a urls.py file in my project and also in my app. I used path() to
map views and organized them properly. I used include() in the main
urls.py to connect app-specific URLs.
Why is URL management important?
It controls navigation of the website, organizes project structure, and helps
in clean and user-friendly links.
Views
Django Views Viva Questions & Answers
1. What is a view in Django?
A view is a Python function or class that takes a web request and returns a
web response (like HTML, JSON, etc). Views contain the logic of what
should be displayed to the user.
2. Types of Views in Django?
There are mainly two types:
Function-Based Views (FBV)
Class-Based Views (CBV)
3. What is Function-Based View (FBV)?
It is a normal Python function that takes a request and returns a response.
def home(request):
return render(request, 'home.html')
4. What is Class-Based View (CBV)?
It is a Python class used as a view. Django provides built-in CBVs like
ListView, DetailView, CreateView etc.
from django.views import View
class HomeView(View):
def get(self, request):
return render(request, 'home.html')
5. What is the difference between FBV and CBV?
Function-Based View Class-Based View
Easy for small logic Better for reusability and complex logic
Procedural approach Object-Oriented approach
6. What is render() in Django views?
render() is used to combine a template with a context dictionary and return
an HttpResponse.
Example:
return render(request, 'template.html', context)
7. What is HttpResponse in Django?
It is a class that returns plain content (text/HTML) as a response.
Example:
from django.http import HttpResponse
def my_view(request):
return HttpResponse("Hello World")
8. What is redirect in Django views?
It is used to redirect the user from one URL to another.
from django.shortcuts import redirect
return redirect('home')
9. How did you create views in your project?
I used function-based views in my project. I created views in views.py file
for different pages like home, menu, cart, orders etc. I used render()
function to display templates.
10. What is context in Django views?
Context is a dictionary passed from view to template. It carries data that
needs to be displayed on the webpage.
context = {'name': 'User'}
return render(request, 'home.html', context)
11. Why are views important in Django?
Views handle the main logic of the project. They connect models with
templates and control what user sees based on request.
SESSIONS
How did you use Sessions in your project?
In my project, I used Django sessions to store cart data for customers.
When a user adds items to the cart, the data is stored in request.session.
This helps maintain cart data even if the user moves to different pages.
What is a Session in Django?
Sessions in Django are used to store and manage user-specific data
across multiple requests from the same user (like cart data, login info,
preferences etc.).
How does Session work in Django?
1. Django creates a unique session ID for every user.
2. This ID is stored in the user's browser as a cookie.
3. Session data (like cart items or user info) is stored in the database (or
cache).
4. Django uses this session ID to fetch user-specific data.
Where is Session Data Stored?
By default in Django → Database table: django_session
But it can also be stored in:
Cache
Filesystem
Cookies
MODELS :
1] WHAT IS MODELS.PY AND MODELS IN DJANGO ?
A] MODELS.PY FILE IS USED TO DEFINE THE STRUCTURE OF OUR
DATABASE
Models in models.py are created using Python classes instead of writing
raw SQL queries
Each model corresponds to the table in the database
category_title category_description category_gif button_label
* EACH MODEL IS NOTHING BUT A PYTHON CLASS ,WHICH
REPRESENTS A TABLE IN DATABASE
* Each field corresponds to a column in the database.
DJANGO CONVERTS EACH CLASS INTO A TABLE STRUCTURE
INTERNALLY
**** What is models.Model?
It is the base class provided by Django. All models should inherit from
models.Model.
2] Models how they work and the main process of accessing them ?
WE FIRST CONFIGURE THE TYPE OF DATABASE IN SETTINGS.PY ----
-This is used to mention which type of database we are using . Sqlite or
postgresql or MySql .
SQLite (django.db.backends.sqlite3)
PostgreSQL (django.db.backends.postgresql)
MySQL (django.db.backends.mysql)
Oracle (django.db.backends.oracle)
3. Running Migrations (Applying Model to Database)
python manage.py makemigrations
This creates a migration file, which contains SQL commands or
instructions for creating tables. It is used to convert model into SQL
instructions
python manage.py migrate:
Executes the SQL commands in the database
This command executes the migration files and applies the changes to the
actual database.
4. Accessing the database [This is used to insert values ,
delete values , update values ,retrieve values ]
We can access the database using ORM [object relational modelling]
CRUD operations [create ,read, delete , update ]
Django ORM converts your Python queries into SQL automatically.
We can access data base using any of the 3 methods
1] DJANGO SHELL ------
2]VIEWS -----
3]FORMS -----
ORM ---- It helps you interact with the database using Python code
instead of SQL. Background work of ORM
Python Code: You write a query using the ORM (like
Student.objects.all()).
Django ORM: This converts the Python query into an SQL statement.
Database Engine: The SQL query is executed in the database.
Database Response: The result (data) is returned to the Django ORM.
Django ORM: The result is converted into Python objects.
Python Code: This data can then be used in views and templates.
If we want to manage the model in the admin interface,
register it in admin.py:
What are fields in models ?
RELATIONSHIPS IN MODELS ?
Explain querysets in Django
Collection of database queries in Django.
Represents collections of objects retrieved from the database.
Provides an API to filter, order, and retrieve data.
Lazy: In Django, lazy evaluation refers to the fact
that QuerySets are lazy objects, meaning they do not hit the
database until they are used. This helps optimize performance, as
Django avoids executing a query until it is necessary.
How did you use Models in your Project? (Sample Answer)
In my project, I created models for Customer, FoodMenu, Orders, Cart, and
Payments. Each model had fields related to that table. I also created
relationships between models using ForeignKey. I used Django ORM to
fetch and store data
PROJECT STRUCTURE
📂 Project Root (Food-order-django)
This is the main directory of our Django project, containing all the essential
files and folders.
📄 db.sqlite3
This is your SQLite database file, which stores all your data, such as
user details, orders, menu items, etc.
SQLite is a lightweight, file-based database that Django uses by
default for local development.
It is automatically created when you run python manage.py migrate to
apply migrations.
Why is it needed?
It stores all your application data persistently.
It is useful for development and small projects where you don’t need
a powerful database like PostgreSQL or MySQL.
📄 .DS_Store
This is a macOS system file that keeps metadata about the folder,
such as icon positions and view settings.
It is not required for your Django project and can be ignored.
Why is it needed?
It is not needed. You can delete it safely.
📂 Project info
This folder might contain documentation, project details, or additional
information about your project.
It is not a default Django folder, so it might have been manually
created to store extra details.
Why is it needed?
It helps keep track of important project details.
If it contains documentation, it helps new developers understand the
project structure.
📄 manage.py *****
This is the most important file in a Django project.
It is a command-line utility that allows you to interact with your
Django project.
Why is it needed?
It helps run important commands like:
o python manage.py runserver → Starts the development server.
o python manage.py migrate → Applies database migrations.
o python manage.py createsuperuser → Creates an admin user.
o python manage.py makemigrations → Creates migration files
when models change.
📄 requirements.txt
This file lists all the Python packages required for your project.
It is used to install dependencies using:
pip install -r requirements.txt
Requirements ----
Django==2.2.7
django-tinymce4-lite==1.7.5
jsmin==2.2.2
pytz==2019.3
sqlparse==0.3.0
Why is it needed?
It ensures that all team members or deployment environments install
the same dependencies.
It makes it easier to deploy the project on different systems.
📂 venv (Virtual Environment)
This is your virtual environment, which isolates your project's
dependencies from the system's global Python environment.
It contains:
o Installed Python packages (like Django, Pillow, etc.)
o A separate Python interpreter for your project.
Why is it needed?
Prevents package conflicts between different projects.
Helps maintain consistent dependencies across different
environments.
Your virtual environment (venv) separates your project's Python
interpreter from the system-wide Python interpreter.
🔹 How Does venv Work?
When you create a virtual environment using:
python -m venv venv
it creates a local copy of the Python interpreter inside your project.
When you activate the virtual environment ( or venv\Scripts\activate
on Windows), your terminal only uses the Python and packages
inside venv, instead of the system-wide ones.
This prevents conflicts between different projects that may require
different package versions.
🔹 What Are Dependencies?
Dependencies are the external Python packages that your project
depends on to work properly.
They are listed in requirements.txt and installed using:
pip install -r requirements.txt
Example dependencies for Django projects:
o Django → Main web framework.
o djangorestframework → For building APIs.
o Pillow → For handling images.
o sqlite3 → For database handling.
📂 pizza
This is the main Django application folder inside your project.
It contains all the code specific to your food-ordering application.
Inside pizza, you will typically find:
__init__.py → Marks this as a Python package.
views.py → Contains the logic for handling user requests.
models.py → Defines the database structure using Django models.
urls.py → Maps URLs to views.
admin.py → Registers models with the Django admin panel.
apps.py → Configuration for the app.
migrations/ → Contains database migration files.
Why is it needed?
It holds the core logic of your application.
Each Django project consists of one or more apps, and "pizza" is one
of them.
_pycache_ folder: The __pycache__ folder in your Django project (or any
Python project) is an automatically generated directory that stores compiled
versions of your Python files. It contains .pyc files, which are bytecode-
compiled versions of your .py files.
When you run a Python file, the following steps occur, which explain how it
links to .pyc files in the __pycache__ folder:
1. Parsing the Python File (.py)
Python first parses your script (.py file) into an Abstract Syntax Tree
(AST).
If there are any syntax errors, Python stops execution.
2. Compiling to Bytecode (.pyc in __pycache__)
If the script is error-free, Python compiles it into bytecode, which is
a lower-level, platform-independent representation of your code.
This bytecode is saved as a .pyc file inside the __pycache__ folder.
4. Executing the Bytecode
The compiled bytecode is then executed by the Python Virtual
Machine (PVM), which interprets and runs it on your system.