Register to get access to free programming courses with interactive exercises

DBMS Key Aspects of Web Development in Python

Suppose we decided to implement a site with ads and want to allow our users to create ads. We already know how to output a page with a form to add an ad. We need to generate HTML using the templating tool. But what do we do after the form data arrives at the server? Where do we store them? We'll get to the bottom of this question in this lesson.

What is a DBMS?

The easiest way to look at it is by using files as an example. We can write all events to a file and read from it when output. This approach has many drawbacks and is very inconvenient to work with. The correct way to work with data is with a database. It is stored in files too, but this process is 100% controlled by a DBMS (database management system). It is the one you need to install before you start work.

The most common systems on the web are PostgreSQL and MySQL. We won't discuss it here because configuring and installing a DBMS isn't as trivial as installing an interpreter. You can find many ready-made instructions on DBMS installation on your operating system.

DBMSs start as separate programs and have a life of their own. These systems can serve many different databases. Usually, one site uses one database, but we can store many databases from several sites in one DBMS. You can interact with a particular database in two ways:

  • Run the DBMS command shell, which allows you to interactively work with commands, write and read data, add a user to the system, and so on. When connecting or after connecting, you need to select the database you want to interact with:

db repl

  • Connect to the DBMS from your program using a driver — a library that communicates with the DBMS. It has a relatively simple interface for performing queries and getting results. Below we'll see how this approach works in practice.

Relationships within the database

PostgreSQL and MySQL belong to the class of relational databases because these DBMSs work based on relational algebra. Without going into theory, we'll say that the data in relational databases store their data in the form of tables. This format is familiar to everyone who has used Microsoft Excel or Google Sheets.

Each table in such a database has its name and a set of named columns. We can refer to columns in a database as fields. For example, we can create a table with ads, give it the name ads and place the following data:

id telephone title
1 132453 Selling a car
2 342341 Buying a yacht
3 908324 Renting a tent

Each row in the table is independent and represents a complete data set. It is a single declaration in our case. Programmers commonly refer to lines as records.

Sign up

Programming courses for beginners and experienced developers. Start training for free

  • 130 courses, 2000+ hours of theory
  • 1000 practical tasks in a browser
  • 360 000 students
By sending this form, you agree to our Personal Policy and Service Conditions

Our graduates work in companies:

<span class="translation_missing" title="translation missing:">Bookmate</span>
<span class="translation_missing" title="translation missing:">Healthsamurai</span>
<span class="translation_missing" title="translation missing:">Dualboot</span>
<span class="translation_missing" title="translation missing:">Abbyy</span>
Suggested learning programs
Developing web applications with Django
10 months
from scratch
under development
Start at any time

Use Hexlet to the fullest extent!

  • Ask questions about the lesson
  • Test your knowledge in quizzes
  • Practice in your browser
  • Track your progress

Sign up or sign in

By sending this form, you agree to our Personal Policy and Service Conditions
Toto Image

Ask questions if you want to discuss a theory or an exercise. Hexlet Support Team and experienced community members can help find answers and solve a problem.