Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Course conclusion
Lecture: Routes

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Once we have our view methods in place and the templates that are going to show their HTML we have to figure out how our URLs
0:07 map over to those view methods and that's where routing comes in. So we can simply refer to the static folder like /static/css/site.css
0:18 and we don't have to do anything for that to be mapped. Flask will already do that for you but maybe we want to go to one of our view methods
0:24 and say this one is going to respond to / and this other one is going to respond to /about. While these pages themselves
0:32 what's actually shown in the HTML may be not be totally fixed and static the actual route will. We're not passing additional data along the route.
0:40 But sometimes, you do want to like in our package, we want to show different packages, and that's actually part of the URL. So we could say
0:48 we want to map /project/<package_name> and what we put in angle brackets here will become variables in the view method and that will be passed along
0:56 whatever value gets put in there automatically by Flask. We can even have constraints. Remember we did our popular packages there?
1:04 Is that if you do a /number, like /1, /7, whatever we want to go and actually call this popular route. However, if for some reason, you pass /about
1:15 it's not going to match that, right? And that's because of the int: there in that screen. That's it. It's also a good idea to define these
1:23 from more specific to more general so Flask is going to hit the first one that it knows about
1:29 and just call that method, so you want to do that as well. by the order in which you register blueprints and things like that.

Talk Python's Mastodon Michael Kennedy's Mastodon