From the course: Advanced Python: Practical Database Examples
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Connect a database to a Python Flask project - Python Tutorial
From the course: Advanced Python: Practical Database Examples
Connect a database to a Python Flask project
- [Instructor] We can connect our Flask application to our database using SQLAlchemy. Within our virtual environment, we can install a special extension that allows us to use SQLAlchemy in our Flask code. Let's activate the environment. We'll install Flask-SQLAlchemy. Then we'll add it as an import to our app.py file. Within our app, there's a few things we need to configure. First, we'll configure the SQLALCHEMY_DATABASE_URI. This URI is like a connection string that allows us to connect to our Postgres database. It's what we fed in to the create engine function before when we used SQLAlchemy previously. we'll also add a SECRET_KEY. This will allow us to securely use SQLAlchemy sessions in our Flask application. Now the value for this key is something we set and we can generate one quickly using a Python Three shell. Let's open one up. We'll import the os module and use os.urandom24 to generate a random value. Let's…
Contents
-
-
-
-
-
Set up Flask in a Python application2m 20s
-
(Locked)
Create a webpage with Flask2m 52s
-
(Locked)
Build a landing page3m 7s
-
(Locked)
Develop additional routes to enhance your application4m 56s
-
(Locked)
Build a project tasks page2m 16s
-
(Locked)
Create a Postgres database2m 1s
-
(Locked)
Instantiate a Postgres table using Python3m 43s
-
(Locked)
Connect a database to a Python Flask project1m 52s
-
(Locked)
Integrate project data from a Database into Flask2m 57s
-
(Locked)
Integrate task data from a database into a Flask app3m 9s
-
(Locked)
Develop add functionality to add a project5m 7s
-
(Locked)
Develop add functionality to add a task2m 10s
-
(Locked)
Challenge: Develop delete functionality1m
-
(Locked)
Solution: Develop delete functionality7m 13s
-
-