From the course: Building RESTful APIs with Flask
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Setting up SQLAlchemy
- [Instructor] Back in PyCharm, we've got the libraries installed, but before we can actually use them we have to do a few configuration steps first. So the first thing I'm going to do is to go back into my code and scroll all the way to the top, and I'm going to add a couple of import statements here. The first one is from flask_sqlalchemy import SQLAlchemy, and the next one is from sqlalchemy import Column, Integer, String, and Float. These are all types that we're going to be needing here in just a few minutes. And then the other thing that I'm going to need is the operating system library, so I'll do import os, and that should do it for my imports. The next step is to add the configuration. So since this is a file-based database, I need to tell my application where to store the file. So go right below where you created the app there on line seven, and let's add something to this very quickly. I'm going to add a variable called basedir, base directory, and I'm going to set it to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Adding an ORM (SQLAlchemy)3m 23s
-
(Locked)
Setting up SQLAlchemy4m 2s
-
(Locked)
Creating the ORM model classes6m 12s
-
(Locked)
Seeding the database with the Flask CLI8m 47s
-
(Locked)
Viewing the database in DB Browser for SQLite5m 8s
-
(Locked)
Retrieving a list of planets from the database6m 20s
-
(Locked)
Serializing SQLAlchemy results with Marshmallow8m 44s
-
-
-
-