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

Week#2 Lec

python lists and function

Uploaded by

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

Week#2 Lec

python lists and function

Uploaded by

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

Week#2

Introduction to Web Development and


Python,HTTP and Web Servers:
Understanding Requests and Responses

Subtitle: Course: Web Programming with Python


Instructor Name: [Nosheen Iqbal]
Course Code: [ABC-111]
Date : 10-09-2024
Agenda

 What is Web Development?  What is HTTP?


 Role of Python in Web Development  How the Web Works: Client-Server
 Types of Web Applications Model
 Introduction to Python Frameworks:  HTTP Requests and Methods
Flask and Django  HTTP Responses and Status Codes
 Tools and Environment Setup  Introduction to Web Servers
 Case Study: Popular Python-Based  Practical Demo: Python Web Server
Web Applications
What is Web Development?

 Definition: The process of building websites or web applications accessible over


the internet.
 Key Aspects:
 Front-end: Client-side development (HTML, CSS, JavaScript).
 Back-end: Server-side logic, databases, and APIs.
 Full-stack: Both front-end and back-end.
The Evolution of Web Development

 Timeline:
Static websites → Dynamic websites → Web applications.
 Trends:
From traditional server-based websites to micro services and server less architectures.
Why Python for Web Development?

 Key Points:
 Versatile & Powerful: Easy to read, write, and maintain.
 Rich Ecosystem: Extensive libraries and frameworks for web development.
 Efficiency: Python reduces development time with its robust frameworks (Flask, Django).
 Community Support: Strong, active community for continuous improvement.
Python in Web Development

 Use Cases:
 Server-side scripting.
 API development.
 Database interaction.
 Handling asynchronous tasks (e.g., Celery, FastAPI).
Types of Web Applications

 Static Websites: Simple, fixed content.

 Dynamic Websites: Content generated on the server.

 Single Page Applications (SPA): Interact with the server via APIs without page reload.

 Progressive Web Applications (PWA): Web apps with native app features.
Introduction to Flask and Django

 Flask: A lightweight, micro-framework for building small to medium applications.

 Advantages: Simple, flexible, minimalistic.

 Use Cases: Prototypes, small web apps, APIs.

 Django: A high-level web framework that encourages rapid development.

 Advantages: Built-in features (ORM, admin panel), scalability, security.

 Use Cases: Large-scale applications, content management systems (CMS).


Flask vs Django

Feature Flask Django


Framework Type Micro-framework Full-stack framework
Fully loaded (ORM, admin,
Built-in Features Minimal, requires extensions
etc.)
Learning Curve Easy for beginners Steeper learning curve
Use Case Small to medium projects Large, complex applications
Tools and Environment Setup

•Python: Install Python 3.x.


•Virtual Environment: Use venv or virtualenv to manage dependencies.
•Code Editor: VSCode, PyCharm, or Sublime Text.
•Package Manager: pip for installing libraries.
•Version Control: Git for code management
What is Syntax?

 In simplest words, Syntax is the arrangement of words and phrases to create well-
formed sentences in a language. In the case of a computer language, the syntax is
the structural arrangement of comments, variables, numbers, operators, statements,
loops, functions, classes, objects, etc. which helps us understand the meaning or
semantics of a computer language.
Python Comments

Single line comments


 A comment is a part of the coding file that the programmer does not want to
execute, rather the programmer uses it to either explain a block of code or to avoid
the execution of a specific part of code while testing.

Example :
Multi-Line Comments

 To write multi-line comments you can use ‘#’ at each line or you can use the multiline
string.
 Example: The use of ‘#’
Python Variables

 Variables are containers that store information that can be manipulated and referenced
later by the programmer within the code.
 In python, the programmer does not need to declare the variable type explicitly, we just
need to assign the value to the variable.

Example:
Cont.
 It is always advisable to keep variable names descriptive and to follow a set of
conventions while creating variables:
 Variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and
_)
 Variable name must start with a letter or the underscore character.
 Variables are case sensitive.
 Variable name cannot start with a number.
Scope of variable:

The scope of the variable is the area within which the variable has been created. Based on this a
variable can either have a local scope or a global scope.
 Local Variable:
A local variable is created within a function and can be only used inside that function. Such a
variable has a local scope.
 Example:
Global Variable

 A global variable is created in the main body of the code and can be used anywhere
within the code. Such a variable has a global scope.
 Example:
if Statement:
 A simple if statement works on following principle,
 execute the block of code inside if statement if the expression evaluates
True.
 ignore the block of code inside if statement if the expression evaluates
False and return to the code outside if statement
 Example:
if-else Statement
 An if……else statement works on the following principle,
 execute the block of code inside if statement if the expression evaluates
True. After execution return to the code out of the if……else block.
 execute the block of code inside else statement if the expression evaluates
False. After execution return to the code out of the if……else block.
 Example:
Nested if Statement

 We can use if, if….else, elif statements inside other if statements.


What is HTTP?

 Definition: Hypertext Transfer Protocol (HTTP) is a protocol used for communication


between clients (browsers) and servers on the web.

 Role: The foundation of data communication for the World Wide Web.

 Characteristics:

 Stateless: Each request is independent of the previous one.

 Application Layer Protocol: Operates on the top of the TCP/IP stack.


The Client-Server Model

 How It Works:
 Client: Sends requests (usually via a browser) to a server.
 Server: Responds to requests by delivering resources (HTML, JSON, etc.).
 Diagram of the Interaction:
 Client (Browser) → HTTP Request → Server (Web Application)
 Server (Web Application) → HTTP Response → Client (Browser
HTTP Requests

 Components of an HTTP Request:

 Request Line: Contains the HTTP method, the resource path, and HTTP version.

 Headers: Key-value pairs that convey additional information (e.g., content type, user agent).

 Body (Optional): Contains data being sent to the server (used in POST, PUT, etc.).
Web Servers

 Definition: A web server is a software that serves content over the web, often running web
applications.

 Common Web Servers:

 Apache: One of the oldest and most widely used web servers.

 NGINX: Known for its performance, used for serving static files and acting as a reverse proxy.

 Python’s Built-in HTTP Server: Great for testing and small-scale applications.
The Role of Web Servers in the HTTP
Process

 Handling Requests: Web servers receive incoming requests and delegate them to the
appropriate backend logic (e.g., Flask or Django application).

 Returning Responses: After processing, the server sends the response back to the client

You might also like