0% found this document useful (0 votes)
3 views

Unit-4 - Connecting SQLite with Django

The document outlines a course on Python Web Development with Django, focusing on connecting SQLite with Django and various related topics. It includes details on the syllabus, course objectives, outcomes, and program outcomes, along with specific units covering database migrations, data fetching, and deploying Django applications. Additionally, it provides prerequisites, instructional resources, and mapping of course outcomes to program-specific outcomes.

Uploaded by

Shaurya Bhati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit-4 - Connecting SQLite with Django

The document outlines a course on Python Web Development with Django, focusing on connecting SQLite with Django and various related topics. It includes details on the syllabus, course objectives, outcomes, and program outcomes, along with specific units covering database migrations, data fetching, and deploying Django applications. Additionally, it provides prerequisites, instructional resources, and mapping of course outcomes to program-specific outcomes.

Uploaded by

Shaurya Bhati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

Noida Institute of Engineering and Technology, Greater Noida

Python Web Development with


Django

Unit: IV

Connecting SQLite with Django

Meghali Das
Course Details
(Asst. Professor)
(B. Tech. 5th Sem)
CSE Department

01/26/2025 Meghali Das Python web development with Django Unit IV 1


Evaluation Scheme

Python Web development with Django (Elective I)


Design Pattern (Elective II)

Meghali Das Python web development with Django Unit IV


01/26/2025 2
Syllabus

UNIT-I: Python libraries for web development

Collections-Container datatypes, Tkinter-GUI applications, Requests-


HTTP requests, BeautifulSoup4-web scraping, Scrapy, Zappa, Dash,
CherryPy, TurboGears, Flask, Web2Py,
Bottle, Falcon, CubicWeb, Quixote, Pyramid.

01/26/2025 3
Meghali Das Python web development with Django Unit IV
Syllabus

UNIT-II: Introduction to Django Framework

Understanding Django environment, Features of Django and Django


architecture, MVC &MTV, Urls and Views, Mapping the views to URLs,
Django Template, Template inheritance Django Models, Creating model for
site, Converting the model into a table, Fields in Models, Integrating
Bootstrap into Django, Creating tables, Creating grids, Creating carousels.

01/26/2025 Meghali Das Python web development with Django Unit IV 4


Syllabus

UNIT-III: Integrating Accounts & Authentication on Django

Introduction to Django Authentication System, Security Problem & Solution


with Django Creating Registration Form using Django, Adding Email Field In
Forms, Configuring email settings, Sending emails with Django, Adding Grid
Layout On Registration Page, Adding Page Restrictions, Login Functionality Test
and Logout.

Meghali Das Python web development with Django Unit IV


01/26/2025 5
Syllabus

UNIT-IV: Connecting SQLite with Django

Database Migrations, Fetch Data From Database, Displaying Data On


Templates, Adding Condition On Data, Sending data from url to view,
Sending data from view to template, Saving objects into database,
Sorting objects, Filtering objects, Deleting objects, Difference between
session and cookie, Creating sessions and cookies in Django.

Meghali Das Python web development with Django Unit IV


01/26/2025 6
Syllabus

UNIT-V: Deploying Django Web Application on Cloud

Creating a functional website in Django, Four Important Pillars to


Deploy, Registering on Heroku and GitHub, Push project from Local
System to GitHub, Working with Django Heroku
Working with Static Root, Handling WSGI with gunicorn, Setting up
Database & adding users

Meghali Das Python web development with Django Unit IV


01/26/2025 7
Branch Wise Application

1. Real time web analytics


2. Digital Advertising
3. E-Commerce
4. Publishing
5. Massively Multiplayer Online Games
6. Backend Services and Messaging
7. Project Management & Collaboration
8. Real time Monitoring Services
9.Live Charting and Graphing
10. Group and Private Chat

Meghali Das Python web development with Django Unit IV


01/26/2025 8
Course Objective

In this semester, the students will

Study how to shows relationships and interactions between frontend &backend

Study to speed up the development process by providing well-tested, proven


development/design paradigms.

Select a specific framework for the development of a given website or webapp.

Analyzing and creating a functional website in Django and deploy Django Web
Application on Cloud.

Meghali Das Python web development with Django Unit IV


01/26/2025 9
Course Outcomes (COs)

At the end of course, the student will be able to:


CO1 : Apply the knowledge of python programing that are vital in understanding Django application

CO2 : Demonstrate web application framework (Django) to design and implement dynamic website

CO3 : Implementing and analyzing the concept of Integrating Accounts & Authentication on Django

CO4 : Understand the impact of web designing by database connectivity with SQLite

CO5 : Analyzing & Creating a functional website in Django and deploy Django Web Application Cloud

01/26/2025 Meghali Das Python web development with Django Unit IV 10


Program Outcomes (POs)

Engineering Graduates will be able to:

PO1 : Engineering Knowledge

PO2 : Problem Analysis

PO3 : Design/Development of solutions

PO4 : Conduct Investigations of complex problems

PO5 : Modern tool usage

PO6 : The engineer and society


01/26/2025 Meghali Das Python web development with Django Unit IV 11
Program Outcomes (POs)

Engineering Graduates will be able to:

PO7 : Environment and sustainability

PO8 : Ethics

PO9 : Individual and teamwork

PO10 : Communication

PO11 : Project management and finance

PO12 : Life-long learning


01/26/2025 Meghali Das Python web development with Django Unit IV 12
COs - POs Mapping

CO.K PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

CO1 2 2 2 3 3 - - - - - - -

CO2 3 2 3 2 3 - - - - - - -

CO3 3 2 3 2 3 - - - - - - -

CO4 3 2 3 2 3 - - - - - - -

CO5 3 2 3 3 3 - - - - - - -

AVG 2.8 2.0 2.8 2.4 3.0 - - - - - - -

01/26/2025 Meghali Das Python web development with Django Unit IV 13


Program Specific Outcomes(PSOs)
Program Specific
S. No. PSO Description
Outcomes (PSO)

1 PSO1 Understand to shows relationships and interactions


between classes or objects of a pattern.

2 PSO2 Study to speed up the development process by


providing well-tested, proven development

3 PSO3 Select a specific design pattern for the solution of a


given design problem

Create a catalogue entry for a simple design pattern


4 PSO4 whose purpose and application is understood.

01/26/2025 Meghali Das Python web development with Django Unit IV 14


COs - PSOs Mapping

CO.K PSO1 PSO2 PSO3 PSO4

CO1 3 - - -

CO2 3 3 - -

CO3 3 3 - -

CO4 3 3 - -

CO5 3 3 - -

01/26/2025 Meghali Das Python web development with Django Unit IV 15


Program Educational Objectives (PEOs)

Program Educational
PEOs Description
Objectives (PEOs)
To have an excellent scientific and engineering breadth so as to comprehend,
PEOs analyze, design and provide sustainable solutions for real-life problems using state-
of-the-art technologies.

To have a successful career in industries, to pursue higher studies or to support


PEOs entrepreneurial endeavors and to face the global challenges.

To have an effective communication skills, professional attitude, ethical values and a


PEOs desire to learn specific knowledge in emerging trends, technologies for research,
innovation and product development and contribution to society.

To have life-long learning for up-skilling and re-skilling for successful professional
PEOs career as engineer, scientist, entrepreneur and bureaucrat for betterment of society.

01/26/2025 Meghali Das Python web development with Django Unit IV 16


Result Analysis(Department Result & Subject Result & Individual result

Name of the faculty Subject code Result % of clear passed

01/26/2025 Meghali Das Python web development with Django Unit IV 17


Pattern of Online External Exam Question Paper (100 marks)

01/26/2025 Meghali Das Python web development with Django Unit IV 18


Pattern of Online External Exam Question Paper (100 marks)

01/26/2025 Meghali Das Python web development with Django Unit IV 19


Pattern of Online External Exam Question Paper (100 marks)

01/26/2025 Meghali Das Python web development with Django Unit IV 20


Pattern of Online External Exam Question Paper (100 marks)

01/26/2025 Meghali Das Python web development with Django Unit IV 21


Pattern of Online External Exam Question Paper (100 marks)

01/26/2025 Meghali Das Python web development with Django Unit IV 22


Prerequisite / Recap

• Student should have knowledge of HTML , CSS and JavaScript .

• Students should have good knowledge of Python Programming and

Python coding experience.

• knowledge of Computer and basic skill.

• Good problem solving Skill .

01/26/2025 Meghali Das Python web development with Django Unit IV 23


Brief Introduction about the Subject with videos

YouTube /other Video Links


• https://youtu.be/eoPsX7MKfe8?list=PLIdgECt554OVFKXRpo_kuI0XpUQKk0ycO

• https://youtu.be/tA42nHmmEKw?list=PLh2mXjKcTPSACrQxPM2_1Ojus5HX88ht7

• https://youtu.be/8ndsDXohLMQ?list=PLDsnL5pk7-N_9oy2RN4A65Z-PEnvtc7rf

• https://youtu.be/QXeEoD0pB3E?list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3

• https://youtu.be/9MmC_uGjBsM?list=PL3pGy4HtqwD02GVgM96-V0sq4_DSinqvf

01/26/2025 Meghali Das Python web development with Django Unit IV 24


Unit IV Content

• Database Migrations.
• Fetch Data From Database.
• Displaying Data On Templates.
• Adding Condition On Data.
• Sending data from url to view.
• Sending data from view to template.
• Saving objects into database, Sorting objects, Filtering objects, Deleting objects.
• Difference between session and cookie, Creating sessions and cookies in
Django.

01/26/2025 Meghali Das Python web development with Django Unit IV 25


Unit IV Objective

In Unit IV, the students will be able to find


• Definitions of terms Database Migrations.
• How Fetch Data From Database & Displaying Data On Templates.
• How to Send data from url to view.
• How to Send data from view to template.
• The idea of a python Library .
• Difference between session and cookie, Creating sessions and cookies in
Django

Meghali Das Python web development with Django Unit IV


01/26/2025 26
Topic Objective

Topic : Database Migrations


• In this topic, the students will gain , The idea of Database migration
is the process of migrating data from one or more source databases
to one or more target databases by using a database migration
service.

01/26/2025 Meghali Das Python web development with Django Unit IV 27


Database Migrations

Database migration: Concepts and principles

 Database migration is the process of migrating data from one or more source databases
to one or more target databases by using a database migration service.

 When a migration is finished, the dataset in the source databases resides fully, though
possibly restructured, in the target databases. Clients that accessed the source
databases are then switched over to the target databases, and the source databases are
turned down.

 A database migration service runs within Google Cloud and accesses both source and
target databases. Two variants are represented: (a) shows the migration from a source
database in an on-premises data center or a remote cloud to a managed database like
Cloud Spanner; (b) shows a migration to a database on Compute Engine
01/26/2025 Meghali Das Python web development with Django Unit IV 28
Database Migrations

Database Migration Process

01/26/2025 Meghali Das Python web development with Django Unit IV 29


Database Migrations

We describe Database migration from an architectural stand pointwise:-

 The services and technologies involved in database migration.


 The differences between homogeneous and heterogeneous database
migration.
 The tradeoffs and selection of a migration downtime tolerance.
 A setup architecture that supports a fallback if unforeseen errors occur
during a migration.
 This document does not describe how you set up a particular database
migration technology. Rather, it introduces database migration in
fundamental, conceptual, and principle terms.

01/26/2025 Meghali Das Python web development with Django Unit IV 30


Database Migrations

Database Migration Architecture:-

Even though the target databases are different in type (managed and unmanaged) and setup,
the 01/26/2025
database migration architecture
Meghali Das andPython
configuration
web development withis the same
Django Unit IV for both cases. 31
Database Migrations

Terminology :-

01/26/2025 Meghali Das Python web development with Django Unit IV 32


Database Migrations

Terminology :-

01/26/2025 Meghali Das Python web development with Django Unit IV 33


Database Migrations

Database migration architecture :-

A database migration architecture describes the various components required for executing a
database migration. This section introduces a generic deployment architecture and treats the
database migration system as a separate component. It also discusses the features of a
database management system that support data migration as well as non-functional
properties that are important for many use cases.

Deployment architecture:-

A database migration can occur between source and target databases located in any
environment, like on-premises or different clouds. Each source and target database can be in
a different environment; it is not necessary that all are collocated in the same environment.
01/26/2025 Meghali Das Python web development with Django Unit IV 34
Database Migrations

01/26/2025 Meghali Das Python web development with Django Unit IV 35


Fetch Data From Database

How to fetch data from database in django?

 In django, we retrieve the data in the views.py file, where we write our
functions.
 To retrieve data from database, first we have to create a url for that. Open the
urls.py file inside the application folder, and create a new path as shown
below:
path('students/', views.students, name="students"),

Now create a function in the views.py file, with the name "students" as shown in

the above path.


01/26/2025 Meghali Das Python web development with Django Unit IV 36
Fetch Data From Database

 Here, we have created a variable form and we have called all the objects of the Student
model. Objects is nothing but the records in the database. Then we have created a
dictionary named context and passed the form variable in the dictionary and passed
that dictionary in the render() function.

 As we have mentioned in the render(), let us create a .html file with the name
index.html and we will be displaying the all the data in the index.html. To display the
data, we will be using the for loop as there will be multiple data in our database.
01/26/2025 Meghali Das Python web development with Django Unit IV 37
Fetch Data From Database

This will print all the data that we had fetched and
stored in the form variable.
01/26/2025 Meghali Das Python web development with Django Unit IV 38
Displaying Data On Templates
Django templates

 Sometimes you want parts of your website to display dynamic data -


that is, data that might be different every time someone opens your
website. In that case, plain HTML won't be enough.

 Luckily, Django templates allow us to do a lot more than just write


HTML. We can display some Python variables that we defined in our
view. Django also gives us some helpful built-in template tags for
displaying data.

 Django template tags allow us to transfer Python-like things into


HTML, so you can build dynamic websites faster and easier
01/26/2025 Meghali Das Python web development with Django Unit IV 39
Displaying Data On Templates

Display the current date and time:

01/26/2025 Meghali Das Python web development with Django Unit IV 40


Displaying Data On Templates

01/26/2025 Meghali Das Python web development with Django Unit IV 41


Adding Condition On Data
 The if template tag is one of the template tags in Django that can be
used to render HTML content for a particular condition. Let us see
how to use the if template tag in Django.

 In a Django template, the if statement is referred to as if tag. You can


use this if tag to render HTML content based on a particular
condition. The syntax of the if template tag is:

01/26/2025 Meghali Das Python web development with Django Unit IV 42


Adding Condition On Data

 In a Django template, you have to close the if template tag. You can write
the condition in an if template tag. Inside the block, you can write the
statements or the HTML code that you want to render if the condition
returns a True value.

 Now let us see an example of the if tag.

 I have created an example where I will enter two numbers and compare
them inside a Django template.

 The following is the Django template where I will submit the two numbers:

01/26/2025 Meghali Das Python web development with Django Unit IV 43


Adding Condition On Data

01/26/2025 Meghali Das Python web development with Django Unit IV 44


Sending data from url to view

Get URL parameters in Django

 In Django, you can also pass parameters as part of the URL. In this Django tutorial, you will
learn how to get URL parameters in Django.

 In various web applications, you might have seen some URLs that end with some
parameters. For example, look at the below URL:

https://www.shop.tsinfo.com/products/12

 The above URL fetches the products page corresponding to a product id i.e. 12. This means
12 is a URL parameter and the result is shown according to this value.

01/26/2025 Meghali Das Python web development with Django Unit IV 45


Sending data from url to view

To get a parameter from the URL, you have to perform the steps explained below:

1. Create and map a path to a view in the application’s URLs file and pass the
parameters to the view

2. Define a function in the view that will take the parameter and pass the parameters to
Django template.

3. Design the Django template to show the results corresponding the passed
parameters.

Let us discuss these steps briefly in the upcoming sections.

01/26/2025 Meghali Das Python web development with Django Unit IV 46


Sending data from url to view

Django URL pass parameter to view

 You can pass a URL parameter from the URL to a view using a path converter.
 But, firstly you have to create a path and map it to a view.
 For this, you have to edit your application’s urls.py file.
 A sample urls.py file will look like this:

01/26/2025 Meghali Das Python web development with Django Unit IV 47


Sending data from url to view

For example, if the requested URL is:

https://www.shop.tsinfo.com/products/12

Then “products” will be the URL endpoint.


1. A path converter defines which type of data will a parameter store. You can compare
path converters with data types. In the above example, the path converter will be
int.
2. You will learn more about various path converters in the upcoming sections.
3. URL parameter name will be the name that you will use to refer to the parameter.
4. The view_name will be the view that will handle the request and the function_name
is the function that will be executed when the request is made to the specified URL
endpoint.
5. The name will be the name of the path that you are going to create.
01/26/2025 Meghali Das Python web development with Django Unit IV 48
Sending data from view to template

We will talk about passing dynamic data to templates for rendering it.

 As we know django is a MVC framework. So, we separate business logic


from presentational logic. We write business logic in views and we pass
data to templates to present the data.

 The data that we pass from views to template is generally called as


"context" data. Let's get started with an example.

 Let's write a simple view that takes user information such as first name,
last name and address and renders it in the template.

01/26/2025 Meghali Das Python web development with Django Unit IV 49


Sending data from view to template

01/26/2025 Meghali Das Python web development with Django Unit IV 50


Sending data from view to template

01/26/2025 Meghali Das Python web development with Django Unit IV 51


Sending data from view to template

 “Render" is the most used function in django. It combines a given template


with a given context dictionary and returns an HttpResponse object with
that rendered text.
 It takes three arguments "request", "template_name" and "context"
dictionary.
 In template we can access the context dict keys as names**or variables**
and display them like "{{ <variable/name>}}".
 Django provides a template tag "for" to provide the for loop functionality in
django templates. You can find the “for loop” syntax below.
 {% for local_name in iterable_name %}
 {{ local_name }}
 {% endfor %}
01/26/2025 Meghali Das Python web development with Django Unit IV 52
Saving objects into database
//ONE LINE SYNTAX TO SAVE DATA

person = Person.objects.create(first_name="John", last_name="Deo")

//YOU CAN ALSO USE BELOW CODE TO SAVE DATA

person = Person(first_name="John", last_name="Deo")


person.save()
 Creating or saving object data in Django is very simple and it can be achieved using
the provided code snippet. In the code snippet, we are using a 'Person' model which
has fields named 'first_name' and 'last_name'. The above code will insert data into
the table where 'John' will be inserted in the 'first_name' column and 'Deo' will be
inserted into the 'last_name' column.
01/26/2025 Meghali Das Python web development with Django Unit IV 53
Sorting objects, Filtering objects, Deleting objects

01/26/2025 Meghali Das Python web development with Django Unit IV 54


Sorting objects, Filtering objects, Deleting objects

01/26/2025 Meghali Das Python web development with Django Unit IV 55


Sorting objects, Filtering objects, Deleting objects

01/26/2025 Meghali Das Python web development with Django Unit IV 56


Session and Cookie

 Cookies, technically called HTTP Cookies are small text files which are created and
maintained by your browser on the particular request of Web-Server. They are stored
locally by your browser, and most browser will also show you the cookies generated
in the Privacy and Security settings of the browser.
 HTTP is a stateless protocol. When any request is sent to the server, over this protocol,
the server cannot distinguish whether the user is new or has visited the site
previously.

 Suppose, you are logging in any website, that website will respond the browser with
some cookies which will have some unique identification of user generated by the
server and some more details according to the context of the website.
 Cookies made these implementations possible with ease which were previously not
possible over HTTP implementation.

01/26/2025 Meghali Das Python web development with Django Unit IV 57


Session and Cookie

How do Cookies work?


Cookies work like other HTTP requests over the Internet. In a typical web-system, the
browser makes a request to the server. The server then sends the response along
with some cookies, which may contain some login information or some other data.
When the browser makes a new request, the cookie generated previously is also
transmitted to the server. This process is repeated every time a new request is made
by the browser.

The browser repeats the process until the cookie expires or the session is closed and
the cookie is deleted by the browser itself.
Then, the cookie applies in all sorts of tasks, like when your login to a website or
when shopping online on the web. Google AdSense and Google Analytics can also
track you using the cookies they generate. Different websites use cookies differently
according to their needs.
01/26/2025 Meghali Das Python web development with Django Unit IV 58
Session and Cookie
What are Sessions?
 After observing these problems of cookies, the web-developers came with a new and more
secure concept, Sessions.
 The session is a semi-permanent and two-way communication between the server and the
browser.
 Let’s understand this technical definition in detail. Here semi means that session will exist until
the user logs out or closes the browser. The two-way communication means that every time the
browser/client makes a request, the server receives the request and cookies containing specific
parameters and a unique Session ID which the server generates to identify the user. The Session
ID doesn’t change for a particular session, but the website generates it every time a new
session starts.
 Generally, Important Session Cookies containing these Session IDs deletes when the session
ends. But, this won’t have any effect on the cookies which have fix expire time.
 Making and generating sessions securely can be a hefty task, and now we will look at Django’s
implementation of the same.

01/26/2025 Meghali Das Python web development with Django Unit IV 59


Creating sessions and cookies in Django.

Creating Cookies in Django

Django bypasses lots of work which otherwise would be required when working
on cookies. Django has methods like set_cookie() which we can use to create
cookies very easily.
The set_cookie() has these attributes:

01/26/2025 Meghali Das Python web development with Django Unit IV 60


Creating sessions and cookies in Django

01/26/2025 Meghali Das Python web development with Django Unit IV 61


Creating sessions and cookies in Django

01/26/2025 Meghali Das Python web development with Django Unit IV 62


Creating sessions and cookies in Django

01/26/2025 Meghali Das Python web development with Django Unit IV 63


Creating sessions and cookies in Django

Creating & Accessing Django Sessions

Django allows you to easily create session variables and manipulate them accordingly.
The request object in Django has a session attribute, which creates, access and edits the
session variables. This attribute acts like a dictionary, i.e., you can define the session names
as keys and their value as values.
Step 1. We will start by editing our views.py file. Add this section of code.

01/26/2025 Meghali Das Python web development with Django Unit IV 64


Creating sessions and cookies in Django

01/26/2025 Meghali Das Python web development with Django Unit IV 65


Daily Quiz

1. Discuss database migration.


2. What is the role of frameworks in python.
3. Discuss any three frameworks.
4. Discuss about concept and process of database migration.
5. Discuss implementation rule session and cookies in django.
6. Discuss the session and cookies.
7. Discuss how to save a object in data base .
8. Discuss the application area of django.
9. Discuss about the Request Http methods in Python.
10. Discuss about http application.

Meghali Das Python web development with Django Unit IV


01/26/2025 66
Weekly Assignment

1. What are the most important uses of Django.


2. What are the disadvantages of Django?
3. What are the different data types used in Django.
4. What are the salient features of Django session and cookies.
5. What are some of the technical features that Django includes

01/26/2025 Meghali Das Python web development with Django Unit IV 67


Topic Link ( YouTube & NPTEL Video Links)

YouTube /other Video Links


• https://youtu.be/eoPsX7MKfe8?list=PLIdgECt554OVFKXRpo_kuI0XpUQKk0ycO

• https://youtu.be/tA42nHmmEKw?list=PLh2mXjKcTPSACrQxPM2_1Ojus5HX88ht7

• https://youtu.be/8ndsDXohLMQ?list=PLDsnL5pk7-N_9oy2RN4A65Z-PEnvtc7rf

• https://youtu.be/QXeEoD0pB3E?list=PLsyeobzWxl7poL9JTVyndKe62ieoN-MZ3

• https://youtu.be/9MmC_uGjBsM?list=PL3pGy4HtqwD02GVgM96-V0sq4_DSinqvf

01/26/2025 Meghali Das Python web development with Django Unit IV 68


MCQ s
1. What is a Django App? 2. Django was introduced by
ADjango app is an extended package with base package
is Django A. Adrian Holovaty
B. Django app is a python package with its own B. Bill Gates
components. C. Rasmus Lerdorf
C. Both 1 & 2 Option D. Tim Berners-Lee
D. All of the above
3. What are Migrations in Django
A. They are files saved in migrations directory.
B. They are created when you run make migrations
command.
C. Migrations are files where Django stores changes to
your models.
D. All of the above

4. Which architectural pattern does django follow


APHP
B. MVT
C. HTML
D. None of the above
Meghali Das Python web development with Django Unit IV
01/26/2025 69
MCQ s

which of these is not a valid backend for caching in django


A. Django.core.cache.backends.sys.memory
B. django.core.cache.backends.db.DatabaseCache
C. django.core.cache.backends.locmem.LocMemCache
D. None of the above

5. Which architectural pattern does django follow


A.PHP
B. MVT
C. HTML
D. None of the above

01/26/2025 Meghali Das Python web development with Django Unit IV 70


MCQ s
6. Python is a : 7. Python is Case Sensitive when dealing with
Development environment Identifiers?
Set of editing tools Yes
Programming Language No
Sometimes Only
None Of the Above

8. What is the OUTPUT of the following Statement? 9. What is the OUTPUT when the following
print 0xA + 0xB + 0xC : Statement is executed?
0xA0xB0xC “abc”+”xyz”
33 abc
ABC abcxyz
000XXXABC abcz
abcxy

10.what is the type of a? a={1,2:3} list


set
dict
syntax error

Meghali Das Python web development with Django Unit IV


01/26/2025 71
Glossary Questions

Top 10 design pattern interview questions

1. Explain Django Architecture?


2. Explain the Django project directory structure?
3. What are models in Django?
4. What are templates in Django or Django template language?
5. What are views in Django?
6. What is Django ORM?
7. What is Django Rest Framework(DRF)?
8. What is the difference between a project and an app in Django?
9. What are different model inheritance styles in the Django?
10.What are Django Signals?
01/26/2025 Meghali Das Python web development with Django Unit IV 72
Expected Questions for University Exam

Top 10 design pattern interview questions

1. Explain Django Architecture?


2. Explain the Django project directory structure?
3. What are models in Django?
4. What are templates in Django or Django template language?
5. What are views in Django?
6. What is Django ORM?
7. What is Django Rest Framework(DRF)?
8. What is the difference between a project and an app in Django?
9. What are different model inheritance styles in the Django?
10.What are Django Signals?
01/26/2025 Meghali Das Python web development with Django Unit IV 73
Summary

Till Now we understand The idea of Database migration is the process of


migrating data from one or more source databases to one or more target
databases by using a database migration service. When a migration is finished,
the dataset in the source databases resides fully, though possibly restructured, in
the target databases. In django, we retrieve the data in the views.py file, where
we write our functions. To retrieve data from database, first we have to create a
url for that. Open the urls.py file inside the application folder. Cookies work like
other HTTP requests over the Internet. In a typical web-system, the browser
makes a request to the server. The server then sends the response along with
some cookies. After observing these problems of cookies, the web-developers
came with a new and more secure concept, Sessions.
The session is a semi-permanent and two-way communication between the
server and the browser.
01/26/2025 Meghali Das Python web development with Django Unit IV 74
References

(1) Tom Aratyn, “Building Django 2.0 Web Applications: Create enterprise-grade, scalable
Python web applications easily with Django 2.0”, 2nd Edition 2018, Packt Publishing.

(2) Nigel George, “Build a website with Django”, 1st Edition 2019, GNW Independent
Publishing Edition.

(3) Ray Yao,” Django in 8 Hours: For Beginners, Learn Coding Fast!, 2nd Edition 2020,
Independently published Edition.

(4) Harry Percival, “Test-Driven Development with Python: Obey the Testing Goat: Using
Django, Selenium, and JavaScript”, 2nd Edition 2019, Kindle Edition.

01/26/2025 Meghali Das Python web development with Django Unit IV 75


THANK YOU

01/26/2025 Meghali Das Python web development with Django Unit IV 76

You might also like