#100DaysOfWeb in Python Transcripts
Chapter: Days 1-4: Flask Intro
Lecture: Create __init.py__
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Okay, we're going to set up each of these files, one at a time. Let's start with the __init__.py file
0:07
cause that's arguably the most important file here. To begin, let's start our virtual environment. If you don't already have it, activate it.
0:18
Okay, in the folder we have demo.py program and virtual environment. Let's head into our program directory
0:26
and there is the __init__.py file we created. So use whatever editor you want to just pop into that
0:33
and what we need to do is we need to first import flask. So if you've ever done a single file flask app before you keep the actual importing of flask
0:46
and the configuration of your app object, your Flask object. That all happens in the one file where your routes is stored and everything. Not so here.
0:56
Your __init__.py file is going to actually configure flask for you and tell the package what's what. Alright. What we want to do is insert.
1:09
So, I forgot for second there I was using Vim. So we're going to do from flask. So from flask import Flask. And then we're going to create.
1:22
This is where we create our application our flask application instance. Now this is going to create the flask instance using the name of __name__.
1:39
Now, here's where the magic is. We're going to do another import here from our program directory that we're already in. Alright, we're already in it.
1:51
We're going to import the routes file. Now this has to happen below where we create the app instance because we need that app instance
2:01
to be created first before we can import any of this. So, the order of our file is to import flask it's to create our Flask app instance
2:12
then once it's created, import the routes file from the program directory that we're in. Alright, that's it. Lets write that.
2:27
Lets cut it. And there it is. All right, next video, next file.