#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Specify the db object in __init.py__
0:00 With the models.py file created
0:02 we now need to actually create that database object
0:05 that DB object, that we used in the models file
0:09 and as I mentioned, that's actually defined, created
0:12 and linked with our Flask app, in the init.py file.
0:18 So let's edit that into there, now.
0:22 And you can see that this is the really basic structure
0:25 the bare bones that we had to get that raw app going
0:29 and now we're going to add some extra stuff to it.
0:32 In order to use Flask SQL app, we need to import it
0:36 so same thing we did in the models file.
0:39 from flask_sqlalchemy import SQLAlchemy
0:47 Now, we need to create that database object
0:51 and the way SQLAlchemy works is that
0:53 it needs to run against the app to create the database
0:57 so we only use that DB object that
1:00 we used in the models file
1:02 so DB is SQLAlchemy app
1:08 the actual Flask app.
1:10 This is where that linking happens.
1:11 This is where the link to the app occurs.
1:15 One thing we haven't actually covered up
1:17 if you think about it, is we haven't actually told it
1:19 what the database is called.
1:21 We haven't said what file to create.
1:24 We haven't done any of that.
1:25 What kind of a database is it?
1:26 Is it SQL? What are we using here?
1:29 And in this instance, we are using SQL, obviously
1:32 so app.config, because we're now configuring this
1:36 into the app, into the Flask app.
1:39 Flask SQLAlchemy right.
1:41 And we have to use this here.
1:43 SQLAlchemy database URI.
1:49 And this is where we define
1:53 what type of database we're using and what it's called.
1:56 All right. So SQLite is what we're using
2:01 and it's going to be a database that we call siteUsers.db.
2:08 All right, you can come up with whatever name you want
2:10 this is the place you reference it
2:12 and this will end up creating a database called site users.
2:17 And last, but not least, in order for all this to work
2:20 with that user model that we created
2:23 we need to actually import or be able
2:26 to import the models file.
2:29 As well, just like we import routes
2:31 now everything can talk to each other.
2:33 Everything within this same view.
2:34 So, from project awesome, import routes and models.
2:39 Save that, and now, we can actually create the database.