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
0:01 command line, getting started concepts.
0:04 So we're going to get started by creating
0:06 the virtual environment, right there.
0:08 python3 -m venv venv, that's kind of a convention
0:12 for the folder name.
0:14 Don't forget to activate it.
0:15 On Mac OS and Linux you do dot
0:17 and then you have bin/activate on Windows.
0:20 Omit the dot and then you have scripts/activate.
0:23 If we have to update pip and setuptools
0:25 they're almost always out of date
0:27 that's always a bummer.
0:28 So then our virtual environment's ready to go.
0:30 We're also going to need Flask in order to write our code.
0:33 So pip install flask
0:35 going to put that in our requirements file in a little bit.
0:37 So now we've got our project all ready
0:40 to run some theoretical Flask app
0:43 but we don't have one yet
0:44 so we're going to create some structure
0:46 and then we're going to write the code.
0:47 So here, we're going to create a mega site
0:50 like a or something.
0:52 Use your imagination of what that might be.
0:55 We're going to create the directory
0:56 that's going to contain all the content.
0:57 We're also going to create the tests here
0:59 I didn't do that in my demo.
1:00 It's nice to have tests, we'll do that later
1:02 in a whole dedicated chapter.
1:05 And in Flask, those typically go as a sibling
1:08 in the directory there
1:10 for the main site content and the tests.
1:13 And then we go into the site folder
1:15 and we create templates, views, viewmodels
1:17 and the static, gives the statics and structure
1:19 create data folder as well.
1:20 Create an requirements, txt and dev.
1:24 And then we're ready to go.
1:26 Here's the structure, very, very similar
1:28 to what you saw me create before
1:29 except for now we have also tests.
1:31 And of course we're going to have the requirements file.
1:34 This allows us to exactly recreate the environment
1:37 on other dev machines, and in the cloud
1:39 or on our server wherever that happens to live.
1:42 So we'll have our requirements that our app actually uses
1:44 this is what the production server needs to run.
1:46 Flask, SQLAlchemy, and passlib
1:48 theoretically in this example.
1:50 And then stuff that maybe the developer needs.
1:53 So Pytest, Pytest-coverage, and webtest.
1:56 And then we can also import the -r option here
2:00 -r requirements.txt.
2:02 So all the production stuff
2:04 plus these three developer libraries.
2:06 I really like this pattern
2:07 and I'm going to use this throughout the course.
2:08 I use this in a lot of my things.
2:10 This is a nice way to organize your requirements.
2:12 In reality, we'd be pinning these versions
2:15 like Flask 1.0, whatever it is right now.
2:17 In the course, in the examples
2:19 I don't want to pin the versions
2:20 because you'll be taking it later
2:22 and what I pick here will be out of date.
2:25 That's a nice practice to follow here.
2:27 And finally, we created a code here.
2:29 So we imported Flask, created a simple Hello World function
2:32 that returns the string Hello World
2:34 give it the route /
2:35 and then run the website.
2:37 That's it, then we just have Python run our app.
2:40 Just Python, and ta-da!
2:43 Hello World, your website is up and running in the browser.
2:46 You can zoom it to have a bigger effect if you like here.
2:49 A very, very simple site
2:51 but it's not just the to get started
2:53 like some people talk about
2:55 it's the proper structure that we're going to need
2:56 to grow into as our site itself grows.