Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Your first Flask site
Lecture: Concepts: CLI starter site

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right, quickly let's review some of these command line, getting started concepts. So we're going to get started by creating
0:07 the virtual environment, right there. Python3 -m venv venv, that's kind of a convention for the folder name. Don't forget to activate it.
0:16 On macOS and Linux you do dot and then you have bin/activate on Windows. Omit the dot and then you have scripts/activate.
0:24 If we have to update pip and setuptools they're almost always out of date that's always a bummer. So then our virtual environment's ready to go.
0:31 We're also going to need Flask in order to write our code. So pip install flask going to put that in our requirements file in a little bit.
0:38 So now we've got our project all ready to run some theoretical Flask app but we don't have one yet so we're going to create some structure
0:47 and then we're going to write the code. So here, we're going to create a mega site like a megasite.com or something.
0:53 Use your imagination of what that might be. We're going to create the directory that's going to contain all the content.
0:58 We're also going to create the tests here I didn't do that in my demo. It's nice to have tests, we'll do that later in a whole dedicated chapter.
1:06 And in Flask, those typically go as a sibling in the directory there for the main site content and the tests. And then we go into the site folder
1:16 and we create templates, views, viewmodels and the static, gives the statics and structure create data folder as well.
1:21 Create an app.py requirements, txt and dev. And then we're ready to go. Here's the structure, very, very similar to what you saw me create before
1:30 except for now we have also tests. And of course we're going to have the requirements file. This allows us to exactly recreate the environment
1:38 on other dev machines, and in the cloud or on our server wherever that happens to live. So we'll have our requirements that our app actually uses
1:45 this is what the production server needs to run. Flask, SQLAlchemy, and passlib theoretically in this example.
1:51 And then stuff that maybe the developer needs. So Pytest, Pytest-coverage, and webtest. And then we can also import the -r option here
2:01 -r requirements.txt. So all the production stuff plus these three developer libraries. I really like this pattern
2:08 and I'm going to use this throughout the course. I use this in a lot of my things. This is a nice way to organize your requirements.
2:13 In reality, we'd be pinning these versions like Flask 1.0, whatever it is right now. In the course, in the examples I don't want to pin the versions
2:21 because you'll be taking it later and what I pick here will be out of date. That's a nice practice to follow here. And finally, we created a code here.
2:30 So we imported Flask, created a simple Hello World function that returns the string Hello World give it the route / and then run the website.
2:38 That's it, then we just have Python run our app. Just Python app.py, and ta-da! Hello World, your website is up and running in the browser.
2:47 You can zoom it to have a bigger effect if you like here. A very, very simple site but it's not just the app.py to get started
2:54 like some people talk about it's the proper structure that we're going to need to grow into as our site itself grows.


Talk Python's Mastodon Michael Kennedy's Mastodon