From the course: Introduction to Python: Learn How to Program Today with Python by Pearson

Unlock this course with a free trial

Join today to access over 25,400 courses taught by industry experts.

Hook up a database

Hook up a database

Okay, so let's make some of that data be persistent across server refreshes and different users and things like that. So let's hook up a database. The databases are for storing data and it's retained if the server gets restarted. We could actually save these as variables hard-coded in the global scope of our app.py or just in our program, but if they were like that, then if their server restarted, they would get initialized back to zero. In a database, you can query for what data you want. For example, users who haven't logged in in over a year, and there are a bunch of different database options you can use. SQLite is just a basic text file, and it's good for really quick databases in development, but don't use it in production. It's just meant for development, testing things out. That's what we're going to use in this lesson, because you don't have to install anything extra, set it all up. It's just a text file, which is nice. There's also Postgres and MySQL. These are really common…

Contents