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

Talk Python's Mastodon Michael Kennedy's Mastodon