Connecting to a relational database and interacting with it
As explained in the Understanding the logic behind the login and signup page section, we want to save the accounts in a database. So, we have to import the database libraries. As mentioned previously, we are using a SQLite3 database. So, first of all, let’s install its Python library by typing the following:
pipenv install sqlite3
Then, simply import the library by writing import sqlite3
in our app.py
file.
Making a SQLite3 database work for us is a quite simple task. For this, we need to open a connection to the database by specifying its name (in our case, userdata.db
) as an argument and creating a cursor to execute operations in it.
On lines 6 and 7 in Figure 13.4, the connection and cursor are created:
Figure 13.4: The connection to the database and its cursor
To recap, the connection (conn
) opens a connection to the database while the cursor (c
) makes it possible to operate...