Modern Python Projects Transcripts
Chapter: Cookiecutter templates
Lecture: Using cookiecutter to generate a project

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's say we want to build a Django website.
0:04 Don't worry if you don't know anything about Django.
0:06 All you need to know is that Django is the most popular Web framework
0:09 in python. So, first we have to find the right template.
0:15 We scroll down to the pantry full of,
0:17 cookie cutter section of the GitHub page.
0:21 And here it says that the best place to start searching for specific and ready to
0:25 use cookie cutter template is GitHub search.
0:28 So, we click this link and we are presented with almost 5000 different GitHub projects related to
0:35 cookie cutter. You don't have to check all of them.
0:38 Usually, only a few first pages are useful,
0:41 so, we can sort this list by most stars.
0:44 And now let's look for a Django cookie cutter.
0:47 The first result is the cookie cutter package itself,
0:49 but the second one is actually a cookie cutter for Django.
0:52 Since Django is a very popular framework,
0:54 it's not surprising that Django cookie cutter template is the most popular one.
0:59 Also, PyDanny. He's the maintainer of the cookie cutter library and a very
1:03 prominent Django developer, who wrote the best Django books available on the market. By using his
1:08 cookie cutter template. We are taking advantage of all his xperience and best practices,
1:13 so, that's a pretty great way to start the project.
1:16 Let's click on this cookie cutter. At the top,
1:20 We can see a list of features,
1:22 and it's impressive. It's using one of the latest versions of Django and Python
1:27 which is good. It adds the SSL certificate.
1:30 It adds a very good Django package for user registration.
1:34 It uses Amazon s3 storage for all the images and other media files in our
1:39 project. It creates a docker compose files, so we can deploy our application with Docker
1:44 and a special file called Procfile.
1:46 If we want to deploy to Heroku. So out of the box we have a bunch
1:52 of tools and plugins that we would have to add to our projects at some
1:56 point anyway. Great. But how do we actually use this cookie cutter template?
2:01 Let's scroll down to the usage section.
2:04 First, we need to make sure that we have cookie cutter installed on our computer
2:07 Cookie cutter is one of those tools that I want to install globally,
2:12 so I will use pipx to install it.
2:19 Next, I need to run cookie cutter command and pass the name of the GitHub
2:23 repository with the template. Let me just copy this command from GitHub and now
2:31 the most important part, cookie cutter will ask you a couple of questions to customize your
2:37 project. Some of them are purely cosmetic.
2:39 For example. The name and email, will only be added in the documentation,
2:43 but some of them are important.
2:45 You can choose between different types of databases,
2:47 enable some optional settings, etcetera.
2:50 All those questions were prepared by the Creator of this specific cookie cutter template,
2:55 so each template will have a different set of questions.
2:58 Let's quickly go to them. So first there is a project name.
3:01 Let's keep the default value of my_awesome_project.
3:04 Now the project slug. This will be used to create the directory.
3:08 Let's keep it the same, description,
3:10 Let's change the description. This is one of those cosmetic changes that will go mostly
3:17 to the documentation author_name.
3:19 Well, this we have to change.
3:20 We are not Daniel Roy Greenfield,
3:23 unless this is actually Daniel following this tutorial,
3:25 but probably not. Domain name, I don't have a domain,
3:30 so let's keep the default for now.
3:32 Email. We have to change. Here,
3:37 We have to select the license.
3:39 So, depending on which one you choose,
3:41 a different license file will be created for you.
3:44 Let's go with the default MIT license on default.
3:47 This option probably means if you are working on Windows or not.
3:51 Probably if you're working on Windows,
3:53 there will be some additional settings, by default,
3:55 It's set to not use windows,
3:57 so let's use the default version.
3:59 If you're using PyCharm select, y,
4:01 like yes, I'm not using PyCharm.
4:04 I will go with No, let's say that we actually want to use Docker.
4:08 Now we have to select which version of postgresSQL database we want to use.
4:11 The latest one is the default,
4:13 but maybe you want to use an older one.
4:15 If you want to run some JavaScript tasks,
4:17 then you can select the task runner.
4:19 I probably don't want to, so let's go with one cloud provider.
4:23 Let's let's go with AWS. Here,
4:26 you can select the mail service in case you want to send emails to your users
4:29 Depending on which option you select,
4:33 this template will probably generate some initial configure that you can use.
4:37 Let's go with Amazon, Whether or not you want to use async.
4:40 Let's let's use the default version whether or not you want to use the drf framework
4:45 now. No, As you can see,
4:49 there are a lot of questions.
4:50 If you don't understand some of them or you're not sure what to choose,
4:53 use the default option. Okay,
5:11 after we answer the last question,
5:13 cookie cutter creates a folder with the scaffolding of our new project,
5:17 and we can start working. So let's see our new folder.
5:26 When you go inside the folder created by the cookie cutter,
5:29 you might be overwhelmed with the number of files that were created.
5:32 And that's understandable. Cookie cutter Django and other popular frameworks try to be as generic
5:38 as possible, so everyone can find a configuration for their specific needs.
5:43 This results in a lot of configuration files for different tools,
5:47 so the best place to start is usually to read me file.
5:50 It explains how to use this template.
5:54 Let's open this one. As you can see,
5:58 the Read Me file is written in the RST format,
6:01 and I don't have a plugin to correctly display it.
6:04 But let's not deal with that for now.
6:07 Let's see what we have here.
6:09 We have a section on settings.
6:11 We have a basic commands. So here it explains that you will need to create
6:17 super User to actually be able to log in.
6:21 Then if you want to run type checks,
6:22 you can just use mypy.
6:24 If you want to run tests or check the test coverage,
6:27 you can run all those commands.
6:30 And then there is some instruction that sends you to the docker section explaining how to
6:35 develop your application. Using Docker If,
6:37 like me, you don't have the RST plugin.
6:39 You can push this code to the GitHub repository and GitHub will actually nicely displayed this readme
6:44 for you. Don't worry.
6:46 If you don't know what some of those things mean,
6:48 You don't have to use all of them.
6:50 You can completely ignore those things and for now,
6:53 start working on your Django website as you always do.
6:56 If you want to learn more about how to use this cookie cutter template,
6:59 we can go to this documentation website.
7:09 Here we actually have the plugin with Docker but you can see we have many more pages
7:14 getting up and running locally with docker settings,
7:19 linters, testing documentation and stuff like that.
7:23 If you want to start working on your Django website,
7:25 you would now do everything thats in a normal Django project.
7:29 But because we use the cookie cutter template,
7:31 we have the latest version of Django.
7:33 We have some packages for out Authentication, bootstrap is already included.
7:37 Also the set up for Amazon s3 is here,
7:40 and we are using the latest pytest for testing.
7:43 And we have coverage plugin to show the test coverage for our code.
7:47 So all those things that a lot of Django projects would have to set up anyway
7:52 is already done for us. It saved us a lot of boring work,
7:55 and now we can focus on actually building our cool website.