Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Routing and URLs
Lecture: Concept: CMS routes
0:00 Often when people are designing their sites
0:02 or making decisions more on the technology
0:04 to use for their site
0:06 they have to think, well, is this mostly a CMS?
0:09 In which case, people are going to be just making pages
0:12 out of the database and it's not really that data-driven
0:16 it's sort of more edited.
0:18 Think WordPress, Squarespace, things like that.
0:22 Or, is it data-driven, like say Amazon?
0:26 Which, should I make my data-driven app
0:28 or should I go and get an off-the-shelf CMS?
0:32 But most of the time you'll find
0:34 you kind of want a little bit of both, actually.
0:37 Sometimes you want to have a few extra pages
0:39 that really don't need to be data-driven
0:42 they're just filled out.
0:43 But you want to put them into your main site
0:45 so you're going to create, what?
0:47 Templates and empty views, or other weird stuff like that.
0:50 So what we can do is we can actually leverage routing
0:53 and create data-driven pages that just show content
0:57 and we can let the marketing team create their landing pages
1:00 just using the CMS.
1:02 And it turns out, it's incredibly easy.
1:04 All we do is create a * subpath route URL structure.
1:08 And it just says, "match everything".
1:11 So we can then apply this route to some function
1:14 and we have a page that is going to fill in all the pieces
1:18 and keep our general design but let them drop in
1:20 pretty much whatever they want, you know, arbitrary HTML.
1:24 And then we're just going to go
1:26 and build that up out of the subpath
1:28 and give us the structure, 'cause that's an easy thing
1:31 to drop in the database and query for.
1:33 Go get the page, if that page is not registered
1:36 in the database, be sure to return a 404.
1:38 Because otherwise you'll have no 404s
1:40 at all on your site again.
1:42 That wouldn't be great.
1:43 Probably those would convert to 500s in bad ways, anyway.
1:48 But, if it does match, you just return the page
1:49 and then you can use that in your page.pt template
1:52 to put all the details in there.
1:54 Super easy, just don't forget
1:56 that this must, must, must go at the end!