Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Your first Pyramid site
Lecture: Demo: CLI starter site

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Alright, we're going to begin creating our project by simply opening up our terminal or command prompt if you're on Windows.
0:08 Want to going to go to the right location. So over here in our demos, this is the Git Repository that you all have access to
0:15 created a thing called Chapter Four: First Site. For each chapter I'm going to have a starter and a final bit.
0:23 So, starters whatever we happen to start with. Later on, we're going to start with our app making major steps.
0:29 Like one point, it'll have a design added to it. At one point, it'll have SQLAlchemy data access added to it.
0:36 We want to start from that point on the next chapter so we'll kind of move along so you always can kind of catch up
0:41 or start from the same place that I'm starting from at any given chapter. So over here we're going to create our site in this final
0:48 and the starter one, there's nothing to do yet. We didn't start from anything. This is from scratch so we'll just have a blank folder there.
0:54 So let's change directories over here. In this, you'll see I have oh-my-zsh. It's detected this is a Git repository.
1:04 It doesn't really matter if your shell does that or not. So what we want to do, is we want to make sure that we have Cookiecutter installed
1:10 so that we can run the various templates. So we'll say pip, maybe pip3, just to be safe. Install, it will ask for an upgrade just in case
1:21 and I'll say --user cause we find it just installs in my user profile. I'm not a machine, which means we don't require sudo.
1:29 Then finally, cookiecutter. I should already have it. Looks like everything's up to date. Yours might have installed it.
1:36 You can always just type cookiecutter and see what you get, right? Something like that. It shows you where it comes from.
1:45 Okay, excellent, we already have this installed and ready to go. So step one, make sure we have Cookiecutter installed. We have that.
1:52 Step two, will be to use one of the Cookiecutter templates. Now if we're over on the Cookiecutter site
1:58 on read the docs, you'll se that there's this thing called pantry full of cookies; cookie cutters. And there's tons of different things.
2:06 So heres a flask thing, heres a bottle heres a pyvanguard; whatever the heck that is. If you look for a pyramid
2:12 there's a whole section on these templates. So here are a bunch that come from the pyramid team and this one down here I actually added myself
2:21 for the Python for Entrepreneurs course. The one we're going to use is this pyramid cookiecutter which is just a Git repository here.
2:27 So we can just take the root of the Git repository and we'll just come down here and say cookiecutter and give it the full URL to the repo.
2:37 Not .git, not that, just the page basically. It says we've already gotten this before can we get a refresh version, yes.
2:45 It's going to ask some questions here. It's going to say, "What is the name of your site?" We're going to call this PyPI
2:52 cause that's going to be the name of our site. Let's call this Python Package Index. Alright, that's going to be our demo
2:59 throughout the whole class here. It's going to say the name that we're going to use in the Python Package in the folder structure stuff
3:07 "Is Python Package Index okay?" Let's go with PyPI; something a lot shorter to type. That says, "Great, we're almost ready.
3:13 "What template language do you want to use?" Default to Jinja2, use to default Chameleon.
3:20 We're going to use Chameleon. You can make another choice if you want. I'll tell you why later why I think Chameleon's the right choice
3:24 but you can pick any one of these three. Hit okay, and it's gone and created a various project structure over here
3:31 so we could type tree and see what we got. It's created this folder which because you can see it's got all this kind of stuff. It's has a
3:41 This is actually a Python package and here's the implementation of it. It has the same name always. Then there's a for the package.
3:50 Then here's our pews, here's our templates here's our static files, and so on. We can go up here and see it says "All right you can go in here
3:57 "and what we want you to do is go into that folder "and create a virtual environment." So, we'll do that. They want to create the virtual environment.
4:08 You can name it a lot of things. .env, or venv, is one of the best choices if you're planning on using PyCharm
4:16 cause it will automatically detect those. I'll make it more explicit and say venv. Now the next thing to do, and so we ask "which Python"
4:26 and Windows asks "where Python" it'll say, "It's the system one." We want to do is use this one, so we need to activate it so we're going to run that.
4:38 Notice my prompt changes here and if I ask the same question I'm getting the one that I just created. So that's good. On Windows you don't say source
4:46 and this is scripts; venv\scripts\activate.bat. Okay, so now we have our virtual environment activated. It's created in the directory
4:59 that is the top level of the package; good. Now all we have to do is to basically register our package and we can run it, register our website.
5:08 We do that by saying Python develop. Now normally you would run an install command here. What we want to do is tell Python
5:16 to leave these files in place and just let us edit it here so we don't have to ever rerun this command again.
5:23 It'll just reference this local working location rather than copying it over to what's called site packages.
5:29 So we do this, it's going to install all the dependencies and get everything setup so we can run it. All right, great, it's installed everything.
5:39 Now we can ask what is installed by saying "pip list" and we've got a bunch of things. We've got pyramid
5:46 and the underlying template language installed. We even have this full local location installed
5:53 with the package PyPI which is our web application itself. One thing that's kind of annoying about virtual environments in Python
6:00 is they always install out of date versions of both setuptools and pip. So, go ahead and update that real quick too.
6:10 There's only 11 versions out of date. What's wrong with that? Okay, so we should be able to run our web app and go interact with it now.
6:19 Let's see "pserv" and we see if that exists. Looks like it does. That got installed when Pyramid got installed, okay?
6:27 And that Pyramid got installed when we ran the setup. Then what we're going to give it is. Let's just look around really quick.
6:32 We're going to give it either the development.ini or the production.ini. Here we want to give it the development one so pserv development.ini.
6:42 There's a small chance this will fail. There's this weird behavior sometimes that the package in the virtual environment
6:48 doesn't get registered exactly right unless you activate, deactivate, and then reactivate it. Fingers crossed this works, let's see.
6:57 Perfect, okay if it doesn't just deactivate the virtual environment reactivate it, and then you'll be totally good.
7:03 All right, so now if we go throw that into our web browser we should be golden. Let's see what we get.
7:08 Ta-dah, the Pyramid Starter Project is up and running and this is the Python Package Index Pyramid Application generated by Cookiecutter; hooray.
7:18 So, we now have this basic structure over here. If we look at it, whew a lot more stuff going on now that we have
7:26 that virtual environment stuff registered. Up here's what matters. This is all the package installed locally and then the virtual environment.
7:35 This is what you really care about, right? We've got our package here. We've registered it and now it's running. We can go edit our template
7:42 to change this look and feel of our CSS. We can go change our view to have different behaviors or to have additional URLs and so on.
7:51 All right, so we're up and running with Pyramid on the command line.

Talk Python's Mastodon Michael Kennedy's Mastodon