Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Welcome to the course
Lecture: Course topics

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's quickly lay out the topics that we're going to cover and add just a little bit of background to each one of them.
0:06 So after this chapter, we're going to quickly talk about how to set up your machine, make sure you have the right version of Python,
0:13 the right editor and also all the starter source code or data that you might need to get going.
0:20 Then we're going to talk about the Flask web framework itself compared to some of the other frameworks like Django, Pyramid, Bottle and so on,
0:28 where does it fit in that world and what are some of the core elements or building blocks of it. We're going to go and create our first Flask site.
0:37 Now, we're going to build a pretty involved and very cool app as we get through this course. But let's not start there, let's just create
0:45 the hello world equivalent of a Flask site and see what all the moving parts are, and then build out something more interesting.
0:53 We're going to focus on some of the techniques and language features of Jinja templates. The idea with Flask is we're going to code
1:02 maybe to a database or a service or something like that, pull back some data and we want to render that to HTML. But you don't do that all on Python.
1:09 Most of the HTML is fixed. You maybe just want to take a list and repeat little elements of it as HTML fragments or conditionally show or hide things
1:17 like if you're logged in or not logged in. So we're going to talk about the Jinja template language and how that fits in the Flask.
1:25 One of the first things that happen in these MVC, Model-View-Controller frameworks like Flask is that a URL request will come in
1:33 both the verb and the URL is going to come in and it's up to this thing called routing to figure out what function is going to handle that request,
1:43 what Python function. So we're going to figure out how to use routing to map URLs to our view methods.
1:48 Flask doesn't do anything for making our site look good, it just delivers whatever HTML we write. So we don't want to have to write all of it.
1:56 We're going to talk about some of the cool frontend frameworks, Bootstrap as well as a couple of others that we could use to make our site look better.
2:05 And we will use some Bootstrap to make out site look good. Almost all the interesting web applications talk to some kind of data backend,
2:13 and we're going to talk to our relational database. So we're going to focus on using SQLAlchemy and its ORM to map Python classes to the database.
2:23 So we're going to see how to define those classes, how to set up the connections, and really do all the queries and inserts and updates,
2:30 everything you need to do to work with SQLAlchemy. SQLAlchemy is great for creating the initial database structure.
2:36 I have a packages and class, and I talk to SQLAlchemy and then create packages table in database.
2:43 But it will not migrate it, it will not change it over time, and if those things become out of sync, your database class and your database schema,
2:51 and the app will crash and freak out and say whoa, whoa, I can't work with this, this database is incompatible with my understanding
2:57 of what it should be. So in order to evolve our database, our database schema, as things grow and change in our application,
3:05 we need to use something called migrations. So we're going to use something called Alembic, which is paired with SQLAlchemy
3:11 to very nicely and in many ways automatically evolve our database schema to stay in line with our application code.
3:18 Web apps that show data, well they're fun, but it's way better if you can accept user input, let people search, let them interact with things
3:26 and so on, create accounts, register, what not. So we're going to talk about HTML forms and how we let users submit data back to our Flask application.
3:37 We're also going to see that the internet is a dangerous place. People will send us invalid data, either by mistake or maliciously.
3:45 So we're going to look at a design pattern called view models that abstract the way or isolate a way the validation for all data
3:53 coming into the server, as well as the data exchange with the template. It's going to be really, really nice.
3:58 And on the client side, we're going to look at some HTML file features that will, with almost no effort, provide really great validation
4:06 for at least the browsers. We want to make sure that our web app is working and stays working. So we're going to write some unit tests,
4:14 we're going to use pytest and some special infrastructure that is baked right into Flask to help us write testable code.
4:21 You'll see that testing web applications can be tricky. We already talked about it, interacting with the database.
4:26 But it also does things like interact with the Flask web framework itself. It expects a request to come in properly structured
4:34 and so on. So we're going to talk about how we can either fake out some of those things or use a special testing infrastructure from Flask
4:42 to make sure that we can write our tests in isolation the way they're meant to work. Once we get out app all working and we want to put it online,
4:49 so we're going to deploy this to a Linux cloud virtual machine using Nginx, uWSGI and Ubuntu. You'll see that not whole lot to it
4:58 and it's really platform to run our web app on. And finally, we're going to talk about converting our web app to MongoDB.
5:06 As we talked about before, this is interesting because MongoDB is a great choice for database backend and it has some really great similarities
5:14 to the SQLAlchemy, so it will be quite similar, but it also will show you the true power of some of our various design patterns
5:21 that we're going to implement, and sometimes we're going to call services, our view models,
5:25 and things like that. And we're going to be able to completely swap out the entire database style, not just implementation but even relational
5:33 versus NoSQL or non-relational databases with just changing a couple of files. So it's going to be really great.
5:39 It's going to be a great sort of way or grounded style and appreciate what we built. Also I'll show you how flexible our data access layer
5:45 will have become by this point. Well, that's it. This is what we're going to cover. I think this is a great set of topics.
5:53 Once you get through all of these, you're going to know pretty much everything that you need to know to write real true production
5:59 data-driven web apps. It's going to be a lot of fun. I hope you're excited. I'm definitely excited to get started on this with you.


Talk Python's Mastodon Michael Kennedy's Mastodon