Adding a CMS to Your Flask Web App Transcripts
Chapter: Advanced markdown
Lecture: Markdown-subtemplates

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we've spoken about some of the limitations of Mark down slow to render it can't reuse content, things like that.
0:10 I'm gonna introduce you to a library that will let us solve all of those problems and more. And the library is called markdown sub template.
0:18 So this is something that I've actually created for my own sites and decided to make a project that everyone can use.
0:24 So how does it work? What's good under this little overview here? We've got some marked down content here says page dot MD as a file.
0:32 But as you'll see, it can just as well be out of a database in memory, something like that. And maybe we have some pieces we went to import
0:39 like this could be the high d. P I. And it could be the transcript section that in the previous example that
0:44 we want to reuse. So we're gonna import those, and then we can feed those to the various frameworks relevant for us into flask.
0:52 Glass is going to render that into its shell. This is the shared layout. Ginger file that gives us the consistent look and feel
1:02 indicates whether or not the users logged in and so on. We're gonna take this converted very efficiently over to HTML and then display it with this
1:10 common look of feel and send that over to the browser. Now, let's go down to this extension bit here and follow through and see some
1:17 of the interesting things happening. But the most important part here is to look at this extensive bility doc for our sake.
1:24 So come down here. What we're interested in is how do we get this marked out? So by default, the library just works as if it's coming from markdown
1:34 files on disk. Doesn't assume you have all the infrastructure that we built up so far in the course. And if you want to use that,
1:41 all you got to do is just point it at at some folder here. Are you pointed this and put these files here and you'd be good to go.
1:49 But that's not what we want, because it's harder to log in and edit files and it is just stuff or point
1:54 of the database. So let's go down here where we can talk to seek welcoming We could also use Mongo, DB or some other way to store it.
2:00 First thing we gotta do is we have to have some way to save a page into the database. Well, guess what?
2:05 We've already done that, and it's called the page class, so we don't have to do anything there.
2:09 That's good. However, what we do have to do to make this work is we've got to go over and write a tiny bit of code less than what you
2:16 actually see on the screen. This is sort of the whole approach. What we've done, a lot of it can be reused to make the shorter.
2:22 But what we have to do is we have to right a little function or a
2:26 couple of functions that allows the markdown sub template library to know how to get and save marked out. So over here we can say,
2:35 given a little girl a subdural, how did we get that? We're just going to go get the page from the database and send back the contents and so on.
2:43 So in order for it to work because it doesn't know what, whether using the file system or we're using a database or maybe that database to seek
2:50 welcome me or Jingo or mongo db right? It could be whatever. So it needs a little tiny bit of help. Doesn't other connection string. For example.
2:58 It needs a little bit of help how to talk to the database. But once that's all set up, then we're pretty good to go.
3:04 So we just have to write this a little bit of code here, and then we're gonna have a much, much better experience or are marked down.
3:13 Will be able to reuse an import content, and it will be much faster as you'll see.

Talk Python's Mastodon Michael Kennedy's Mastodon