#100DaysOfWeb in Python Transcripts
Chapter: Days 37-40: Introduction to Pyramid framework
Lecture: Creating the app: Via the CLI

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now as I said before, we can either use the cli
0:03 or command line terminal, or we can use PyCharm.
0:07 I'll take you through getting our site set up
0:09 in the command line interface first
0:12 and then we'll come back and we'll see it again in PyCharm
0:14 because like I said, I really want you to see the steps
0:17 and understand what's happening here.
0:18 So let's go over to our demo folder here
0:21 and see, nothing here yet, but there's about to be
0:25 so the idea is we're going to go to this folder here
0:28 and we're going to use Cookiecutter.
0:30 Well, let's figure out what the Cookiecutter
0:32 template is that we're going to need.
0:34 If we come over here, I've already pulled up the docs
0:36 Cookiecutter.readthedocs.io, and you can see
0:39 here it is, better project templates.
0:41 And there's a section called Pantry Full of Cookiecutters.
0:45 And there are, if you look at the scroll bar here
0:48 lots of different types of projects you could create
0:50 there's C#, there's ELM, there's Kotlin
0:53 but the majority is in Python, and there's a bunch
0:56 around Pyramid, so we could start with the
0:59 Cookiecutter SQLAlchemy version
1:02 that uses Jinja2, and URL Dispatch.
1:05 The one I like is the one that I've already visited here
1:07 is the Pyramid Cookiecutter starter
1:09 that's the one we're going to use
1:11 we also could use ZODB, or substance
1:15 or there's even one, look at this
1:17 from the Talk Python course for the Python
1:19 for entrepreneurs course, we built up
1:21 we spent like 20 hours building this really
1:23 elaborate application there on Pyramid
1:25 and then this is the Cookiecutter that will generate
1:28 you basically the end product, so this one
1:30 takes you way far down the line
1:31 but we're not going to start there
1:32 we're going to start with the starter
1:34 so you learn the framework.
1:36 So all we got to do to use Cookiecutter
1:38 is grab the GitHub template, or GitHub URL for the template
1:42 and notice here, if there's a Cookiecutter.JSON in the root
1:46 chances are this is a Cookiecutter project.
1:48 So, now we've got to make sure that we have Cookiecutter
1:50 so we'll say pip install --user cookiecutter
1:54 you might also want to throw in a --upgrade just in case.
1:59 Looks like I already have it, okay.
2:01 The other thing is, you want to make sure
2:02 that Cookiecutter is in the path.
2:06 If you're on a POSIX system, Linux, MacOS, whatever
2:10 you can say where cookiecutter, on Windows it's
2:12 which cookiecutter, but notice, 'cause I did the --user
2:15 it's in my library, Python, that version
2:18 now I can type, I get to it, I find it because of this
2:22 right, sometimes this just works out
2:24 sometimes you got to modify your path
2:26 so if you look at my path, you can see
2:28 that that folder is in there, so all the stuff
2:31 I pip install --user, it always finds.
2:34 So you might have to adjust your path
2:35 either on Windows or on Mac or Linux
2:38 so that you can actually get to
2:39 Cookiecutter when you install it.
2:41 So we've got Cookiecutter installed
2:42 we got it in our path, now we just want to
2:44 create our project, and we'll say Cookiecutter
2:47 and we're going to paste the entire URL to our template.
2:50 So cookiecutter https://github.com/Pylons/pyramid-cookiecutter-starter
2:53 Let's hit it with this one.
2:55 Now this is asking what is your project name.
2:57 Now remember I called this Bill Tracker Pro Demo Edition
3:02 or something to that effect, and it says
3:04 alright, well we're going to guess that the package name
3:06 the code name, the name in code, is going to be
3:09 bill_tracker_pro, we can just say bill tracker
3:14 if we want to keep it simple, just to
3:16 show you that it can be different.
3:17 Now I strongly recommend that you use Chameleon templates.
3:21 Jinja2 are more popular, I'll tell you why
3:24 I prefer Chameleon later, but I think
3:27 they're just way more HTTP friendly
3:29 way less symbol noise, things like that
3:31 so you can pick whichever one you want
3:33 but if you want to follow along exactly
3:35 Chameleon is what you should pick here.
3:37 And it says we can have a back end, or no back end
3:40 for now we're just going to go with none
3:42 we'll do that more manually, and boom, look at that.
3:45 It says we've created this directory
3:47 and sure enough it has, it's created this directory.
3:50 Here's the stuff to manage the project
3:53 the package of our site, and here's the actual code
3:56 like the views and templates and whatnot.
3:59 Okay, and all of that was based on
4:01 the answers we gave to Cookiecutter here.
4:03 So the first thing we want to do is
4:05 be able to run it, it says alright
4:07 well you need to create a virtual environment
4:09 and I have a better virtual environment command
4:13 which is this thing here, because it will
4:16 create the environment activate it
4:18 and make sure we have the latest pip
4:20 so we'll just run that, actually, careful careful
4:23 we're going to be inside the bill tracker here
4:25 same directory as the setup.
4:28 Then we want to register this package
4:30 so we can run setup.py, so say python
4:34 setup.py, make sure your virtual environment is activated
4:36 remember that's what my little command did here
4:39 in addition to just creating it
4:40 we want to pass it the develop command.
4:42 What that means is, instead of copying
4:44 all of this stuff somewhere else
4:46 which means we'll have to reinstall it
4:47 every time we want to see a change
4:49 it's just going to do a symlink over to this folder
4:51 and say look right here, so as we edit the code live
4:53 it's just going to constantly change
4:55 as far as Python's concerned.
4:56 So it's going to do that registration
4:58 and install all the dependencies.
5:01 We now have this egg info, that's a good sign
5:03 that something worked here, so let's just try
5:05 to run it, we'll say pserve, which got installed
5:08 when we ran the setup, right, that installed
5:09 the dependencies which included Pyramid
5:11 which gives us pserve, and you can see
5:13 pserve is now there, and we want to send it
5:16 the development one, look at that.
5:20 Let's pull that up and see what we got.
5:21 Ta-da, we have a Pyramid starter project!
5:23 Welcome to Bill Tracker Pro, a Pyramid application
5:27 generated by Cookiecutter.
5:29 Right, that's how we start our application
5:31 and get rolling from the command line.
5:34 If we now want to go further and just edit this
5:36 let's say in PyCharm, we just take the folder
5:39 that contains the setup.py as well
5:41 and we drop it onto PyCharm here
5:44 and notice PyCharm's already detected
5:46 it's a Pyramid web app, and we'll be able
5:47 to run it, if we look in the terminal
5:49 you'll see that it's using the right
5:54 Python, because of the convention of the name
5:57 of the virtual environment there, and so on.
6:00 The one thing that is a little bit off is
6:02 when you create it this way, PyCharm
6:04 doesn't necessarily know that that should be
6:07 source root, it should also be
6:11 a resource root, and that should be a template.
6:16 Here we go, but, if I push the button, will it work?
6:18 You bet it does, and I'll click there
6:22 boom, it's running once again.
6:23 Alright, so, that's our project from the command line
6:27 next I'll show you how to do this in PyCharm.
6:29 Spoiler alert, there's way fewer steps.