CTE 323
PYTHON PROGRAMMING LANG.
LECTURE 1
LECTURE RECAP
Topics covered in CTE 313:
Lecture 1:
◦ Course Information & Introduction to Python Programming.
◦ Input, processing and Output
Lecture 2:
◦ Decision Making and Loop
Lecture 3:
◦ Functions
Lecture 4:
◦ Files
Lecture 5:
◦ Classes and Object
Lecture 6:
◦ GUI programming
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 2
Course Outline: CTE 323
Introduction
Python databases
Python and JavaScript
Web application with Django
3
LECTURE 1
Topics to cover:
Introduction
4
Introduction
Python is one of the widely used languages to build web
applications.
You can use it to perform several tasks; you can even do Web
Development by using Python.
You can use Python to build web apps in several ways, such as
for server-side web apps,
RESTful web APIs, etc.
As there are so many ways that you can use Python to build
web applications, it can be a bit difficult and overwhelming to
get started.
5
Web Development
Web Development is a very vast field, but in general, it means developing
applications that can be accessed via the internet on a web browser.
A web application has two components, frontend, and backend.
Frontend
The frontend is the part of a web application that deals with what users can
see and interact with and how those interactions should appear.
It is what the users see on their web browser when they visit a URL to access a
web application.
The front-end developer of a web application is concerned with managing
interactions with web servers, fetching data, displaying it in the web
application, and sending it to the webserver to be saved or manipulated such
as a tweet, blog post, etc.
6
Backend
The backend is the part of a web application that deals with its server-side
aspects.
It is the aspect where Web Development using Python really shines.
The backend handles storing, retrieving, and formatting data in an agreed-
upon format so that the data can be parsed and understood by other
applications.
Since, in a web server, data is exchanged via HTTP, the backend of a web
application needs to be able to parse an HTTP request, understand its content,
and operate accordingly on the data. These operations may include storing,
validating, updating, deleting, and retrieving data, and more.
7
These two aspects (frontend and backend) can be used to build applications in multiple
ways.
One of these ways will be doing everything on the server.
This includes storing the frontend, i.e., HTML, CSS, and JavaScript, on the server,
creating templates and putting data in those templates by using a database, building
the entire web page on the server, and sending the code to the browser over the
network.
This is fine for a smaller web application but for larger applications, this could lead to
slower performance.
Another way is to use web servers to return data in a specified format, which is then
parsed and displayed on the frontend by using templates and data returned from the
server. This is done by the front-end developer with the help of JavaScript. It frees up
the server-side processing and makes the entire job a lot faster.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 8
What makes Python suitable for Web
Development?
Short Learning Curve
One of the reasons for Python being so popular is that it is very easy to
learn. Python, as a programming language, was designed to be clear and
concise. Its syntax is considered the primary reason for its readability. It
emphasizes clarity over convention.
Rich Ecosystem
Python has a large number of ready-made libraries for developers to
use to solve numerous problems; developers can distribute their
libraries as well. All these things allow developers to not focus on
issues that are already solved but to use their time and energy to build
applications and solve problems that are unique to them.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 9
Development Speed
As Python offers a lot of libraries, developers can invest more focus in building
applications. Python’s syntax and tooling also enhance development speed. This edge
in the speed of development has been one of the major factors that have led to
Python’s popularity.
Large Community
Python has a large community of developers using it, which is because of its wide
acceptance. The community has a lot of Python veterans and developers who have
been using the language for quite a long time. Because of such a large community of
developers, any questions that new developers have can be answered by these
professionals with varying levels of proficiency in the language, which can help you
learn web development with Python.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 10
Python Web Frameworks
A framework is a collection of pre-written packages and modules that are bundled to
work together to solve a bunch of common problems. These common problems usually
involve a lot of tedious tasks, such as logging, validation, persistence, etc., for which
developers need to write code in their projects.
In this scenario, a framework offers a set of packages of code that allow developers to
solve these problems consistently across all projects.
In Python web application development, Python is mostly used for building the
backend.
Python frameworks take care of dealing with tasks that are related to backend
application development, such as parsing HTTP requests, generating HTTP responses,
accessing the database, authentication, authorization, etc. These tasks are so common
that they are implemented in various backends.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 11
There are multiple Python Web Development Frameworks for backend
development, ranging from small, focused, and micro frameworks to big
and batteries-included frameworks.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 12
Popular Python Web Framework
Flask
Flask is one of the most popular HTTP Python Web Development Framework.
Since it is a micro framework, it does not have a lot of features baked into it that
the other web frameworks might have, such as templating, account authorization,
authentication, etc.
However, this does not mean that Flask is a poor choice for you to use as it gives
you the freedom to use any library or even custom code to deal with those
concerns.
For example, you can choose a custom ORM library to handle the database, and
at the same time, you can use your code to deal with validating data. In other
words, you are no longer tied down to always use a pre-built solution; rather, you
can also choose to build your solutions.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 13
Django
 Django is a Python HTTP framework for building the backend of web applications. It is a
batteries-included framework that includes a lot of components, such as ORM,
templating engine serializer, etc., for implementing various tasks.
 One of the reasons for Django’s popularity is that it is quite easy to learn and use,
especially because of its pluggable architecture.
 Django allows you to build small decoupled apps that can be included or plugged into
larger projects. In Django, you get apps and projects, where an app is a small self-
contained codebase, while a project is a collection of multiple apps.
 Django ships with some very powerful libraries for performing several tasks. One of the
most popular among these libraries is the object-relational mapper (ORM.)
 An ORM is a software package that takes care of making database queries and mapping
the results back to Python objects, which can be used inside a Python codebase. An ORM
is easier to use with other Django libraries, including templating engine, validation,
admin panel, etc.
 Django boosts developer productivity by allowing them to focus less on trivial low-level
details and more on solving business problems. This is exactly what has made Django
extremely popular.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 14
Flask vs Django
Although both Django and Flask are quite popular and useful, it can be a little
difficult to figure out when to use them.
In general, you can use both of them for building the backend of your web
application. However, these frameworks are well suited for particular use cases.
Django is a full-stack web framework, whereas Flask is a light-weight, extensible
framework.
Django follows lots of design patterns, and hence you learn a lot of exciting
concepts.
Django is heavy-weight, whereas, with Flask, you have to build everything on
your own.
Django has been around since 2005; Flask kept its foot in 2010 – about 5 years
later.
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 15
Django Flask
Full-stack web framework that follows
the batteries-included approach.
Light-weight framework with
minimalistic features.
Developers already have access to the
most common features that makes
development faster.
Developers can explore and keep
control of the core of the application.
Django comes with a ready-to-use
admin framework that can be
customized.
Flask doesn’t have any such feature to
handle administration tasks.
It comes with a built-in template
engine that saves a lot of
development time.
Flask’s template engine Jinja2 is based
on Django’s template engine.
It allows users to divide a single
project into multiple small
applications which makes them easy
to develop and maintain.
Each project can be a single
application, however, multiple models
and views can be added to the single
application.
The Django-admin tool is a built-in
bootstrapping tool with which
developers can build web applications
without any external input.
Admin features are not as prominent
as in Django.
The built-in ORM system enables
developers to use any database and
perform common DB tasks without
having to write long queries.
With Flask, developers have to work
with different databases by using ORM
systems for Python and SQLAlchemy
as the SQL toolkit. SQL queries have to
be written for common tasks.
Django is a production-ready
framework.
Though some people claim so, Flask is
single-threaded and may not perform
too well under heavy load. Check
out this link to know more.
Django is considered to be more
popular because it provides many out
of box features and reduces time to
build complex applications.
Flask is a good start if you are getting
into web development. There are
many websites built on the flask and
gain heavy traffic, but not as much
compared to the ones in Django.
Django is not suitable for projects
where requirements change
dynamically.
With Flask, a simple application can
be later changed to add more
functionality and make it complex. It
provides flexibility to expand the
application quickly.
Developers can not afford changeless
flexibility as the modules provided by
Django.
Developers are free to use any plugins
and libraries and build functionalities
in a flexible way.
Django is suited for more significant
projects that need much functionality.
For more straightforward projects, the
features might be an overdose.
Flask is a simple, unopinionated
framework; it doesn’t decide what
your application should look like –
developers do.
Django is suited for bigger projects
that need a lot of functionality. For
simpler projects, the features might
be an overdose.
Simple applications can be built with
ease and do not require too much
coding.
Django framework ensures
developers use best practices as
everything has a template.
Flask is more open-ended and
developers may or may not follow the
best practices.
QUESTIONS
A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 19

CTE 323 - Lecture 1.pptx

  • 1.
  • 2.
    LECTURE RECAP Topics coveredin CTE 313: Lecture 1: ◦ Course Information & Introduction to Python Programming. ◦ Input, processing and Output Lecture 2: ◦ Decision Making and Loop Lecture 3: ◦ Functions Lecture 4: ◦ Files Lecture 5: ◦ Classes and Object Lecture 6: ◦ GUI programming A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 2
  • 3.
    Course Outline: CTE323 Introduction Python databases Python and JavaScript Web application with Django 3
  • 4.
    LECTURE 1 Topics tocover: Introduction 4
  • 5.
    Introduction Python is oneof the widely used languages to build web applications. You can use it to perform several tasks; you can even do Web Development by using Python. You can use Python to build web apps in several ways, such as for server-side web apps, RESTful web APIs, etc. As there are so many ways that you can use Python to build web applications, it can be a bit difficult and overwhelming to get started. 5
  • 6.
    Web Development Web Developmentis a very vast field, but in general, it means developing applications that can be accessed via the internet on a web browser. A web application has two components, frontend, and backend. Frontend The frontend is the part of a web application that deals with what users can see and interact with and how those interactions should appear. It is what the users see on their web browser when they visit a URL to access a web application. The front-end developer of a web application is concerned with managing interactions with web servers, fetching data, displaying it in the web application, and sending it to the webserver to be saved or manipulated such as a tweet, blog post, etc. 6
  • 7.
    Backend The backend isthe part of a web application that deals with its server-side aspects. It is the aspect where Web Development using Python really shines. The backend handles storing, retrieving, and formatting data in an agreed- upon format so that the data can be parsed and understood by other applications. Since, in a web server, data is exchanged via HTTP, the backend of a web application needs to be able to parse an HTTP request, understand its content, and operate accordingly on the data. These operations may include storing, validating, updating, deleting, and retrieving data, and more. 7
  • 8.
    These two aspects(frontend and backend) can be used to build applications in multiple ways. One of these ways will be doing everything on the server. This includes storing the frontend, i.e., HTML, CSS, and JavaScript, on the server, creating templates and putting data in those templates by using a database, building the entire web page on the server, and sending the code to the browser over the network. This is fine for a smaller web application but for larger applications, this could lead to slower performance. Another way is to use web servers to return data in a specified format, which is then parsed and displayed on the frontend by using templates and data returned from the server. This is done by the front-end developer with the help of JavaScript. It frees up the server-side processing and makes the entire job a lot faster. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 8
  • 9.
    What makes Pythonsuitable for Web Development? Short Learning Curve One of the reasons for Python being so popular is that it is very easy to learn. Python, as a programming language, was designed to be clear and concise. Its syntax is considered the primary reason for its readability. It emphasizes clarity over convention. Rich Ecosystem Python has a large number of ready-made libraries for developers to use to solve numerous problems; developers can distribute their libraries as well. All these things allow developers to not focus on issues that are already solved but to use their time and energy to build applications and solve problems that are unique to them. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 9
  • 10.
    Development Speed As Pythonoffers a lot of libraries, developers can invest more focus in building applications. Python’s syntax and tooling also enhance development speed. This edge in the speed of development has been one of the major factors that have led to Python’s popularity. Large Community Python has a large community of developers using it, which is because of its wide acceptance. The community has a lot of Python veterans and developers who have been using the language for quite a long time. Because of such a large community of developers, any questions that new developers have can be answered by these professionals with varying levels of proficiency in the language, which can help you learn web development with Python. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 10
  • 11.
    Python Web Frameworks Aframework is a collection of pre-written packages and modules that are bundled to work together to solve a bunch of common problems. These common problems usually involve a lot of tedious tasks, such as logging, validation, persistence, etc., for which developers need to write code in their projects. In this scenario, a framework offers a set of packages of code that allow developers to solve these problems consistently across all projects. In Python web application development, Python is mostly used for building the backend. Python frameworks take care of dealing with tasks that are related to backend application development, such as parsing HTTP requests, generating HTTP responses, accessing the database, authentication, authorization, etc. These tasks are so common that they are implemented in various backends. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 11
  • 12.
    There are multiplePython Web Development Frameworks for backend development, ranging from small, focused, and micro frameworks to big and batteries-included frameworks. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 12
  • 13.
    Popular Python WebFramework Flask Flask is one of the most popular HTTP Python Web Development Framework. Since it is a micro framework, it does not have a lot of features baked into it that the other web frameworks might have, such as templating, account authorization, authentication, etc. However, this does not mean that Flask is a poor choice for you to use as it gives you the freedom to use any library or even custom code to deal with those concerns. For example, you can choose a custom ORM library to handle the database, and at the same time, you can use your code to deal with validating data. In other words, you are no longer tied down to always use a pre-built solution; rather, you can also choose to build your solutions. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 13
  • 14.
    Django  Django isa Python HTTP framework for building the backend of web applications. It is a batteries-included framework that includes a lot of components, such as ORM, templating engine serializer, etc., for implementing various tasks.  One of the reasons for Django’s popularity is that it is quite easy to learn and use, especially because of its pluggable architecture.  Django allows you to build small decoupled apps that can be included or plugged into larger projects. In Django, you get apps and projects, where an app is a small self- contained codebase, while a project is a collection of multiple apps.  Django ships with some very powerful libraries for performing several tasks. One of the most popular among these libraries is the object-relational mapper (ORM.)  An ORM is a software package that takes care of making database queries and mapping the results back to Python objects, which can be used inside a Python codebase. An ORM is easier to use with other Django libraries, including templating engine, validation, admin panel, etc.  Django boosts developer productivity by allowing them to focus less on trivial low-level details and more on solving business problems. This is exactly what has made Django extremely popular. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 14
  • 15.
    Flask vs Django Althoughboth Django and Flask are quite popular and useful, it can be a little difficult to figure out when to use them. In general, you can use both of them for building the backend of your web application. However, these frameworks are well suited for particular use cases. Django is a full-stack web framework, whereas Flask is a light-weight, extensible framework. Django follows lots of design patterns, and hence you learn a lot of exciting concepts. Django is heavy-weight, whereas, with Flask, you have to build everything on your own. Django has been around since 2005; Flask kept its foot in 2010 – about 5 years later. A.O. AGBEYANGI - CHRISLAND UNIVERSITY (CSC) 15
  • 16.
    Django Flask Full-stack webframework that follows the batteries-included approach. Light-weight framework with minimalistic features. Developers already have access to the most common features that makes development faster. Developers can explore and keep control of the core of the application. Django comes with a ready-to-use admin framework that can be customized. Flask doesn’t have any such feature to handle administration tasks. It comes with a built-in template engine that saves a lot of development time. Flask’s template engine Jinja2 is based on Django’s template engine. It allows users to divide a single project into multiple small applications which makes them easy to develop and maintain. Each project can be a single application, however, multiple models and views can be added to the single application.
  • 17.
    The Django-admin toolis a built-in bootstrapping tool with which developers can build web applications without any external input. Admin features are not as prominent as in Django. The built-in ORM system enables developers to use any database and perform common DB tasks without having to write long queries. With Flask, developers have to work with different databases by using ORM systems for Python and SQLAlchemy as the SQL toolkit. SQL queries have to be written for common tasks. Django is a production-ready framework. Though some people claim so, Flask is single-threaded and may not perform too well under heavy load. Check out this link to know more. Django is considered to be more popular because it provides many out of box features and reduces time to build complex applications. Flask is a good start if you are getting into web development. There are many websites built on the flask and gain heavy traffic, but not as much compared to the ones in Django.
  • 18.
    Django is notsuitable for projects where requirements change dynamically. With Flask, a simple application can be later changed to add more functionality and make it complex. It provides flexibility to expand the application quickly. Developers can not afford changeless flexibility as the modules provided by Django. Developers are free to use any plugins and libraries and build functionalities in a flexible way. Django is suited for more significant projects that need much functionality. For more straightforward projects, the features might be an overdose. Flask is a simple, unopinionated framework; it doesn’t decide what your application should look like – developers do. Django is suited for bigger projects that need a lot of functionality. For simpler projects, the features might be an overdose. Simple applications can be built with ease and do not require too much coding. Django framework ensures developers use best practices as everything has a template. Flask is more open-ended and developers may or may not follow the best practices.
  • 19.
    QUESTIONS A.O. AGBEYANGI -CHRISLAND UNIVERSITY (CSC) 19