Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Routing and URLs
Lecture: Concept: CMS routes

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Often when people are designing their sites or making decisions more on the technology to use for their site
0:07 they have to think, well, is this mostly a CMS? In which case, people are going to be just making pages
0:13 out of the database and it's not really that data-driven it's sort of more edited. Think WordPress, Squarespace, things like that.
0:23 Or, is it data-driven, like say Amazon? Which, should I make my data-driven app or should I go and get an off-the-shelf CMS?
0:33 But most of the time you'll find you kind of want a little bit of both, actually. Sometimes you want to have a few extra pages
0:40 that really don't need to be data-driven they're just filled out. But you want to put them into your main site so you're going to create, what?
0:48 Templates and empty views, or other weird stuff like that. So what we can do is we can actually leverage routing
0:54 and create data-driven pages that just show content and we can let the marketing team create their landing pages just using the CMS.
1:03 And it turns out, it's incredibly easy. All we do is create a * subpath route URL structure. And it just says, "match everything".
1:12 So we can then apply this route to some function and we have a page that is going to fill in all the pieces
1:19 and keep our general design but let them drop in pretty much whatever they want, you know, arbitrary HTML. And then we're just going to go
1:27 and build that up out of the subpath and give us the structure, 'cause that's an easy thing to drop in the database and query for.
1:34 Go get the page, if that page is not registered in the database, be sure to return a 404. Because otherwise you'll have no 404s
1:41 at all on your site again. That wouldn't be great. Probably those would convert to 500s in bad ways, anyway.
1:49 But, if it does match, you just return the page and then you can use that in your page.pt template to put all the details in there.
1:55 Super easy, just don't forget that this must, must, must go at the end!


Talk Python's Mastodon Michael Kennedy's Mastodon