#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Specify the db object in __init.py__

Login or purchase this course to watch this video and the rest of the course contents.
0:00 With the models.py file created we now need to actually create that database object that DB object, that we used in the models file
0:10 and as I mentioned, that's actually defined, created and linked with our Flask app, in the init.py file. So let's edit that into there, now.
0:23 And you can see that this is the really basic structure the bare bones that we had to get that raw app going
0:30 and now we're going to add some extra stuff to it. In order to use Flask SQL app, we need to import it so same thing we did in the models file.
0:40 from flask_sqlalchemy import SQLAlchemy Now, we need to create that database object and the way SQLAlchemy works is that
0:54 it needs to run against the app to create the database so we only use that DB object that we used in the models file so DB is SQLAlchemy app
1:09 the actual Flask app. This is where that linking happens. This is where the link to the app occurs. One thing we haven't actually covered up
1:18 if you think about it, is we haven't actually told it what the database is called. We haven't said what file to create. We haven't done any of that.
1:26 What kind of a database is it? Is it SQL? What are we using here? And in this instance, we are using SQL, obviously
1:33 so app.config, because we're now configuring this into the app, into the Flask app. Flask SQLAlchemy right. And we have to use this here.
1:44 SQLAlchemy database URI. And this is where we define what type of database we're using and what it's called. All right. So SQLite is what we're using
2:02 and it's going to be a database that we call siteUsers.db. All right, you can come up with whatever name you want this is the place you reference it
2:13 and this will end up creating a database called site users. And last, but not least, in order for all this to work with that user model that we created
2:24 we need to actually import or be able to import the models file. As well, just like we import routes now everything can talk to each other.
2:34 Everything within this same view. So, from project awesome, import routes and models. Save that, and now, we can actually create the database.


Talk Python's Mastodon Michael Kennedy's Mastodon