Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Routing and URLs
Lecture: Concept: Routing to add a custom CMS
Login or purchase this course to watch this video and the rest of the course contents.
0:00 As you saw we can use routing to actually capture arbitrary URLs. Use our Jinja templates and our common layout to actually create a very simple CMS
0:12 with almost no code. Here's most of the implementation honestly right here. So we want to create a route and instead of just having slash some variable
0:20 we're going to say this variable is of type path and that means it's going to capture not just stuff between a given set of slashes
0:27 or on the end of a URL but the entire thing after a forward slash. So that lets us grab the URL in case none of the other ones already match
0:37 and then what we're going to do is just go to the database and say "Hey if we entered something for this URL and if so
0:43 let's get a page title and a piece of content and just show it wrapped up in our common layout." How cool is that?
0:50 And it took us definitely less than 10 minutes to build it from scratch. Now we didn't build the editing backend
0:56 that lets you type in the title, the URL and the page content probably is marked down and rendered as HTML. Y'know that is a simple exercise
1:04 it's not a ton of work for you to do that. This is enough to get you started. This is the hard part technically speaking
1:09 this is the part you have to understand that's tricky and then from there on out it's pretty straightforward.
1:14 This shows you some of the power of routing in Flask.