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
0:01 we can use routing to actually capture arbitrary URLs.
0:05 Use our Jinja templates and our common layout
0:08 to actually create a very simple CMS
0:11 with almost no code.
0:13 Here's most of the implementation honestly right here.
0:15 So we want to create a route
0:16 and instead of just having slash some variable
0:19 we're going to say this variable is of type path
0:22 and that means it's going to capture
0:23 not just stuff between a given set of slashes
0:26 or on the end of a URL
0:28 but the entire thing after a forward slash.
0:31 So that lets us grab the URL
0:33 in case none of the other ones already match
0:36 and then what we're going to do
0:37 is just go to the database and say
0:39 "Hey if we entered something for this URL and if so
0:42 let's get a page title and a piece of content
0:45 and just show it wrapped up in our common layout."
0:48 How cool is that?
0:49 And it took us definitely less than 10 minutes to build it
0:51 from scratch. Now we didn't build the editing backend
0:55 that lets you type in the title, the URL
0:57 and the page content probably is marked down
0:59 and rendered as HTML.
1:01 Y'know that is a simple exercise
1:03 it's not a ton of work for you to do that.
1:04 This is enough to get you started.
1:06 This is the hard part technically speaking
1:08 this is the part you have to understand that's tricky
1:10 and then from there on out it's pretty straightforward.
1:13 This shows you some of the power of routing in Flask.