Adding a CMS to Your Flask Web App Transcripts
Chapter: Advanced markdown
Lecture: Concept: Markdown subtemplate integration

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's talk about rendering markdown content this time in a much better way. Remember Version one? We just took Mark down to the library and said,
0:08 We're gonna on every request, take the page, get it's marked down content and turn into HTML.
0:14 We saw, however, there was a bunch of drawbacks that one that's super slow for large pages. We want that to be faster.
0:23 Another one is there's no possibility of reusing or composing marked on content from other markdown
0:30 content. You can't like, do that import thing we've been doing. So we switched over to the markdown sub template package and in order to use it
0:38 now it's quite simple. We just like before in our view model still get the page. But instead of just saying page dot convents is the HTML,
0:46 then we moved, passing that to the mark down to library. Now we go. We let the markdown sub template library completely manage that.
0:54 So we're going to go do the engines, they get Paige and give it to you girl Now for that's actually work.
1:00 The markdown sub template library needs to know how to talk to our database to determine if that page exists as well as traverse the imports.
1:09 Du. The replacements do the cashing. There's lots of stuff that it needs to do.
1:12 So we're going to have to create a very simple class that derives from sub template
1:17 storage. And that means we have to write basically four methods to meaningful ones, get markdown text and get shared markdown.
1:25 And we can just delegate back toe our CMS service. So, for example, here, when they the system needs to know about a page,
1:32 we just say, Give us that page from the database of exists, we return its contents. If it doesn't exist, we just say Sorry, it doesn't exist now.
1:41 This is good. But in order to make the markdown sub template, use this new implementation of the storage engine We have to go and at the app
1:51 start up, say create one of these and go to the markdown sub template storage and say the set the storage engine. To be this one that we wrote here,
2:00 then it's off to the races. Superfast composable is really, really nice.


Talk Python's Mastodon Michael Kennedy's Mastodon