Adding a CMS to Your Flask Web App Transcripts
Chapter: Course conclusion
Lecture: Improving markdown

Login or purchase this course to watch this video and the rest of the course contents.
0:00 we saw the challenges of both writing HTML and having broken HTML that breaks our page by switching to mark down and mark down is beautiful.
0:10 We used the mark down to library. We're able to pass over the mark down and have it turn into HTML so we
0:16 could continuously edit the nice version markdown. But show what we have. Teoh HTML However,
0:22 there was a couple of things that were either big disadvantages or features we wanted The
0:27 big disadvantage was speed we saw that are marked down conversion was really, really slow. Like for a simple page 2015 20 pages long,
0:38 that was gonna take 800 milliseconds, every request that is not going to scale. That is not gonna make our users happy. None of that was okay. Also,
0:46 we might want to re use content, we say, Well, we're gonna have this block a code appear on,
0:50 like 10 different pages. Do we want to write and maintain 10 copies of it Of course not. We want to write it in one place and have it
0:57 show up all over the place. But mark down doesn't do that. So we brought in this markdown sub template library.
1:04 So with markdown September what we saw that it automatically handles the cashing on Lee re compute stuff when it needs to,
1:10 which makes it much, much faster. We were getting 10 milliseconds instead of 800 millisecond response times,
1:16 which is really good close to 100 times faster for some of the requests we also saw. It has this import statement, which allows us to build arbitrary,
1:24 really deep, nested levels of imports. Right imports can use imports and weaken. Compose these reusable elements of our CMS in a much,
1:33 much better way. Also has the ability to pass in variables and replace them in the page like Jinja. But we didn't take advantage of that.
1:41 So this marked down sub template library was exactly what we needed to make this work
1:45 much better. Couple of things band to do in order to use it in our view model. When we were getting the content of the page,
1:52 the very last line here self that HTML. Instead of just saying that's the page dot content or mark down to dot convert over
2:00 the page contents. We actually just go to the markdown sub template. We say Go to the engine and get the page.
2:06 Give it the URL and long is everything set up correctly. It handles it from there. You don't worry about it.
2:11 Don't do anything else. It's going to go get the page from the database, figure out the contents, do the import stuff and convert it and just drop the
2:19 final HTML right there in self dot HTML. Now it doesn't magically know how to talk to our database or some other thing.
2:27 We have to give it a little tiny bit of helps. We created this markdown sub template DB storage class.
2:33 It had four abstract method. The most important one was get marked down text. We just go to our service and say, Give me the page. There's no page,
2:40 There's no contents. There's a page right out of the contents. That's it. The super super simple.
2:46 But we did this because we needed toe teach markdown sub template, how to talk to our database and where our data stored.
2:54 So now it knows how to go given a euro or a template path, as it calls it, how to go and actually get the underlying page that corresponds
3:02 to that from the database once we got this done, this is not enough. It doesn't magically just know. Here's a class that drives him right thing.
3:09 So it's gonna work with to do a tiny bit of work and laptop you. I we call on our main method. This in it marked on tablets,
3:15 would just create one of these classes, goes to the markdown storage and says,
3:19 Set the storage to this thing and then it will use that to figure out where the content lives, how to get it both for a regular content,
3:27 shared content and so on. And that's it. Now we've made our mark down back to CMS. Much, much better. Faster. More features composable, reusable,


Talk Python's Mastodon Michael Kennedy's Mastodon