Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Introducing the Flask framework
Lecture: Building block: Routes and URLs

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next core building block is route. Now, conceptually, maybe this should go first but I wanted to show you what the view method
0:08 looked like because routes go on them. So here we have a route, and it has a URL pattern. We've got /project, that part is fixed.
0:16 It's always going to be the same in the URL. The part that comes after that, that's actually defining what we want to pull from the database.
0:24 So like, /project/boto or /project/sqlalchemy That last part, the package name is actually going to be
0:33 passed in as a string to our details function here. And then we're going to do some processing with that. Of course, you know, go to the database
0:40 maybe tell them there's a 404 if they try to get a package that literally doesn't exist. Otherwise we're just going to show them the details.
0:47 So for routes, we use app.route as a decorator with a unique URL pattern, an optional HTTP verb. Here we don't see one but previously
0:57 in that register example, we said it only accepts post not get requests so only the form submission not the original request.
1:04 And then some route data like URL packaging. If we want to serve up static files, we don't have to
1:09 define a route for that, just /static will automatically be used by Flask but of course you can go customize that as well.


Talk Python's Mastodon Michael Kennedy's Mastodon