Django Unit 1
Django Unit 1
Unit: I
Priya Singh
Course Details
(Asst. Professor)
(B. Tech. 5th Sem)
CSE Department
Research Paper Published paper in IEEE International conference “Application of neural network for flight
simulation”(Scopus Indexed)
Published paper in IEEE International conference “New Morphological Technique for
Medical Image Segmentation”(Scopus Indexed)
Published paper in National conference on “Performance study on Morphological Based
Technique for Image Segmentation”.
12/23/2023 4
Priya Singh Python web development with Django Unit I
Syllabus
Analyzing and creating a functional website in Django and deploy Django Web
Application on Cloud.
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
PO8 : Ethics
PO10 : Communication
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 - - - - - - -
CO1 3 - - -
CO2 3 3 - -
CO3 3 3 - -
CO4 3 3 - -
CO5 3 3 - -
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 life-long learning for up-skilling and re-skilling for successful professional
PEOs career as engineer, scientist, entrepreneur and bureaucrat for betterment of society.
• 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
• Collections-Container datatypes,
• Tkinter-GUI applications,
• Requests-HTTP requests,
• BeautifulSoup4-web scraping,
• Scrapy, Zappa, Dash, CherryPy, TurboGears,
• Flask, Web2Py,
• Bottle, Falcon, CubicWeb, Quixote, Pyramid.
• In this topic, the students will gain , The idea of this module
implements specialized container datatypes providing alternatives
to Python’s general purpose built-in containers,
5 Frame ----The Frame widget is used as a container widget to organize other widgets.
Label
6 The Label widget is used to provide a single-line caption for other widgets. It can also
contain images.
7 Listbox --- The Listbox widget is used to provide a list of options to a user.
Geometry Management
The most elegant and simplest of above listed libraries is Requests. We will be using requests
library in this article. To download and install Requests library, use following command:
pip install requests
Scrapy is a Python framework for large scale web scraping. It gives you all the tools
you need to efficiently extract data from websites, process them as you want, and
store them in your preferred structure and format.
As diverse the internet is, there is no “one size fits all” approach in extracting data
from websites. Many a time ad hoc approaches are taken and if you start writing
code for every little task you perform, you will eventually end up creating your own
scraping framework. Scrapy is that framework.
With Scrapy you don’t need to reinvent the wheel.
This isn't really "serverless" (servers run AWS Lambda), but with an AWS Lambda
function, you don't have to spin up servers, install packages, make sure security
patches are up to date, and most of all: you don't have to pay for server time that
isn't used.
A cloud server has to run all the time, whether or not someone visits your website. But
an AWS Lambda function only runs when requested.
• Before we can deploy our web app on AWS Lambda with Zappa, first we need
to install Zappa and a web framework to build our web app with. In this
project, we are going to build a Flask app, so Flask needs to be installed too.
You can install both of these packages with pip, the Python package manager.
• Using a terminal, create a project directory called zappa_app and cd into it.
Create a virtual environment, activate it, and install Zappa and Flask.
• mkdir zappa_appcd zappa_apppython -m venv venvsource venv/bin/activate#
on windows: venv\Scripts\activatepip install flaskpip install zappa You can
verify the installation by calling two help commands at the terminal.
• flask --helpzappa --help
Next, we'll build a simple web app with Flask. This web app is super small and basic,
but it will give you an idea of how Zappa and AWS Lambda works.
Create a file called app.py in the main project directory zappa_app we created
earlier. Inside app.py, paste the following code. This super simple Flask app creates
one webpage that displays the text Yeah, that is Zappa! Zappa! Zap! Zap!. You can
modify the text between the <h1> .... </h1> tags to include any message you want.
Copy the code below into app.py.
# app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return '<h1>Yeah, that is Zappa! Zappa! Zap! Zap!</h1>' # We only need this for
local development.if __name__ == '__main__': app.run()
12/23/2023 Priya Singh Python web development with Django Unit I 46
Zappa (continue….)
Dash Setup
If Dash is not already installed in your terminal, then install the below mentioned Dash libraries.
As these libraries are under active development, install and upgrade then frequently. Python 2
and 3 are also supported.
pip install dash==0.23.1 # The core dash backend
pip install dash-renderer==0.13.0 # The dash front-end
12/23/2023
Priya Singh Python web development with Django 54
Unit I
CherryPy
• CherryPy allows developers to build web applications in much the same way
they would build any other object-oriented Python program.
• This results in smaller source code developed in less time. It is being used in
many production websites.
• CherryPy is a web framework of Python which provides a friendly interface to
the HTTP protocol for Python developers.
• It is also called a web application library.
• It is one of the oldest web frameworks for Python, which provides clean
interface and reliable platform.
12/23/2023 Priya Singh Python web development with Django Unit I 55
CherryPy (continue….)
Strengths of CherryPy
The following features of CherryPy are considered as its strengths −
Simplicity
Developing a project in CherryPy is a simple task with few lines of code developed as per the
conventions and indentations of Python.
CherryPy is also very modular. The primary components are well managed with correct logic
concept and parent classes are expandable to child classes.
Power
CherryPy leverages all the power of Python. It also provides tools and plugins, which are
powerful extension points needed to develop world-class applications.
Open-source
CherryPy is an open-source Python Web Framework (licensed under the open-source BSD
license), which means this framework can be used commercially at ZERO cost.
Community Help
It has a devoted community which provides complete support with various types of
questions and answers. The community tries to give complete assistance to the
developers starting from the beginner level to the advanced level.
Deployment
There are cost effective ways to deploy the application. CherryPy includes its own
production-ready HTTP server to host your application. CherryPy can also be
deployed on any WSGI-compliant gateway.
CherryPy comes in packages like most open-source projects, which can be
downloaded and installed in various ways which are mentioned as follows −
•Using a Tarball
•Using easy_install
•Using Subversion
12/23/2023 57
Priya Singh Python web development with Django Unit I
Turbo Gears
TurboGears is a Python web application framework, which consists of many
modules. It is designed around the MVC architecture that are similar to Ruby on
Rails or Struts. TurboGears are designed to make rapid web application
development in Python easier and more supportable.
TurboGears is a web application framework written in Python.
TurboGears follows the Model-View-Controller paradigm as do most modern web
frameworks like Rails, Django, Struts, etc. This is an elementary tutorial that covers
all the basics of TurboGears.
TurboGears is a web application framework written in Python. Originally created by
Kevin Dangoor in 2005, its latest version TurboGears (ver 2.3.7) is managed by a
group of developers led by Mark Ramm and Florent Aide.
TurboGears follows the Model-View-Controller paradigm as do most modern web
frameworks like Rails, Django, Struts, etc.
• CubicWeb contains data repository that enables access to one or more data sources
such as SQL databases, LDAP repositories, filesystems, Google App Engine’s DataStore,
and even other CubicWeb instance repositories. A data repository can be configured
to either be accessed remotely using Pyro (Python Remote Objects) or act as a
standalone server, that in turn can be accessed either via a standalone web engine or
directly. Usually the web engine and the repository are run in the same process.
• Download
• The latest stable version of Quixote (Python 3 only) is version 3.5 (3.4 sig),
released 2021-06-12.
• The version of the 2.x series (Python 2 compatible) is version 2.9.1 (2.9.1 sig),
released 2016-04-18.
• The latest version of the 1.x series is Quixote is version 1.3, released 2008-
08-21.
• The latest test version of Quixote is version 3.6a2 (3.6a2 sig), released 2021-
12-20
• This may take you far, especially while learning. As your application grows,
Pyramid offers many features that make writing complex software take less
effort.
• 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
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
(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.