2 added
1 removed
Original
2026-01-01
Modified
2026-02-21
1
<p>In this lesson, you'll learn what components make up the backend when written in Python. We'll get acquainted with the key terms we'll need for the course.</p>
1
<p>In this lesson, you'll learn what components make up the backend when written in Python. We'll get acquainted with the key terms we'll need for the course.</p>
2
<h2>Web servers</h2>
2
<h2>Web servers</h2>
3
<p>Most web applications rely on the client-server model:</p>
3
<p>Most web applications rely on the client-server model:</p>
4
<ul><li><strong>Client</strong>: The user opens the browser and sends a request</li>
4
<ul><li><strong>Client</strong>: The user opens the browser and sends a request</li>
5
<li><strong>Server</strong>: The request from the browser goes to<strong>the web server</strong>, which begins to process it</li>
5
<li><strong>Server</strong>: The request from the browser goes to<strong>the web server</strong>, which begins to process it</li>
6
</ul><p>Some languages embed the web server directly into the application, but most interpreted languages use an external program. There are several standalone web servers, but the most popular is<strong>Nginx</strong>. It handles incoming requests, serves static files, and distributes requests to web applications.</p>
6
</ul><p>Some languages embed the web server directly into the application, but most interpreted languages use an external program. There are several standalone web servers, but the most popular is<strong>Nginx</strong>. It handles incoming requests, serves static files, and distributes requests to web applications.</p>
7
<h2>WSGI</h2>
7
<h2>WSGI</h2>
8
<p>If the web application backend runs on Python, we usually find a<strong>WSGI server</strong>running<strong>WSGI applications</strong>behind the web server. Let's take a closer look at what that is.</p>
8
<p>If the web application backend runs on Python, we usually find a<strong>WSGI server</strong>running<strong>WSGI applications</strong>behind the web server. Let's take a closer look at what that is.</p>
9
<p>The<strong>WSGI</strong>(<em>Web Server Gateway Interface</em>) is the abstraction under which the requests get answered. It is a Python function that takes a request and returns a response. The basic WSGI application looks like this:</p>
9
<p>The<strong>WSGI</strong>(<em>Web Server Gateway Interface</em>) is the abstraction under which the requests get answered. It is a Python function that takes a request and returns a response. The basic WSGI application looks like this:</p>
10
<p>Let's take a closer look at this snippet of code:</p>
10
<p>Let's take a closer look at this snippet of code:</p>
11
<ol><li>Everything about a particular query comes in the environ argument</li>
11
<ol><li>Everything about a particular query comes in the environ argument</li>
12
<li>The `start_response' function sets the response parameters - its size and content type</li>
12
<li>The `start_response' function sets the response parameters - its size and content type</li>
13
<li>The function returns an iterator that returns the response line by line</li>
13
<li>The function returns an iterator that returns the response line by line</li>
14
</ol><p>The web application is easy to create:</p>
14
</ol><p>The web application is easy to create:</p>
15
<ul><li>Use the popular WSGI server<a>gunicorn</a></li>
15
<ul><li>Use the popular WSGI server<a>gunicorn</a></li>
16
<li>Put the function in the example.py file</li>
16
<li>Put the function in the example.py file</li>
17
<li>Run the command gunicorn -w 4 example:app</li>
17
<li>Run the command gunicorn -w 4 example:app</li>
18
</ul><h2>Web Framework</h2>
18
</ul><h2>Web Framework</h2>
19
<p>Above, we saw a simple web application. Even though it works, it'll return identical text for every query. Writing something more complex in this style would be problematic, though doable. To make a backend developer's life easier and to help them implement typical applications, we use<strong>frameworks</strong>- libraries that define a ready-made application structure.</p>
19
<p>Above, we saw a simple web application. Even though it works, it'll return identical text for every query. Writing something more complex in this style would be problematic, though doable. To make a backend developer's life easier and to help them implement typical applications, we use<strong>frameworks</strong>- libraries that define a ready-made application structure.</p>
20
<p>The developer only needs to insert his code snippets into this structure, and the application structure is ready to use. The most popular web frameworks for Python are<strong>Django</strong>and<strong>Flask</strong>.</p>
20
<p>The developer only needs to insert his code snippets into this structure, and the application structure is ready to use. The most popular web frameworks for Python are<strong>Django</strong>and<strong>Flask</strong>.</p>
21
<p>Web frameworks can do many different things:</p>
21
<p>Web frameworks can do many different things:</p>
22
<ul><li>Perform routing</li>
22
<ul><li>Perform routing</li>
23
<li>Simplify work with headers and query data</li>
23
<li>Simplify work with headers and query data</li>
24
<li>Form responses in various formats</li>
24
<li>Form responses in various formats</li>
25
<li>Store query histories in files for statistics and debugging</li>
25
<li>Store query histories in files for statistics and debugging</li>
26
-
</ul><p>What else is in the backend besides query processing? Most of the time, there are two tools:</p>
26
+
</ul><h2>ORM and Templating Tool</h2>
27
+
<p>What else is in the backend besides query processing? Most of the time, there are two tools:</p>
27
<ul><li><strong>ORM</strong>(<em>Object-Relational Mapping</em>) is a tool for working with records in databases. It represents records as objects that are understandable by Python</li>
28
<ul><li><strong>ORM</strong>(<em>Object-Relational Mapping</em>) is a tool for working with records in databases. It represents records as objects that are understandable by Python</li>
28
<li><strong>Templating</strong>is a tool that allows you to write HTML and CSS in separate files and modify their contents. It allows you to create a layout once and then programmatically retrieve different pages from the layout</li>
29
<li><strong>Templating</strong>is a tool that allows you to write HTML and CSS in separate files and modify their contents. It allows you to create a layout once and then programmatically retrieve different pages from the layout</li>
29
</ul><p>Django and some other web frameworks already include an ORM and templating engine.</p>
30
</ul><p>Django and some other web frameworks already include an ORM and templating engine.</p>