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