Modern Python Projects Transcripts
Chapter: Cookiecutter templates
Lecture: You can build your own template
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
So far, We saw how to use an existing cookie cutter template to generate the project. But all those templates that we saw in the GitHub were created by
0:09
someone. So if you want, you can create your own template to, why would you write your own template?
0:15
You might do this when none of the existing ones seems like a good choice. If you're always building very specific projects,
0:22
maybe you need your own template from scratch. Or maybe you like one of the templates. But you want to change a few things.
0:28
For example, you want to use a different library here and there. Or maybe you always remove the same feature from a given template,
0:35
and you would prefer to have a template without those features in the first place. You can't change the template that belongs to someone else,
0:42
but you can always fork it, make the necessary modifications and use that version instead. So how do we write a cookie cutter template?
0:51
If you go to the documentation of the cookie cutter, there is a section called Create a Cookie Cutter from scratch.
0:59
Unfortunately, it's very basic, and it has this to be continued sentence at the end, so maybe by the time you're watching this,
1:06
it has much more detailed information. But basically the simplest cookie cutter template is just a folder with this weird name.
1:15
Cookie cutter.project_slug In this double curly brackets. You put some files inside that folder and you publish it on GitHub.
1:23
Now when you run cookie cutter command with GitHub URL, It will replace this weird cookie cutter.projects_slug folder name
1:30
with a real name of your project, and inside you will have the same files that you put on GitHub. But of course, cookie cutter can do much more.
1:39
You can replace the content of some files or file names with variables that you provide when generating the project. You can also remove some files.
1:47
For example, when the templates lets you choose between different database engines and you choose
1:52
MySQL instead of Postgres.. Then there is no point to keep the postgres setting file, so you can safely remove them.
2:00
If you want to learn how to create your own cookie cutter template,
2:03
I can recommend you another course from the talk Python catalog called using and mastering
2:08
cookie cutter. Apart from a very good explanation of different features of the cookie cutter library, one of the chapters shows you step by step,
2:17
how to write your own template from scratch. And as you can see, it takes over one hour, so there's a lot of things that you can learn.