#100DaysOfWeb in Python Transcripts
Chapter: Days 37-40: Introduction to Pyramid framework
Lecture: A tour of a Pyramid project

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We'll begin our extended demo of building the Bill Tracker Pro Demo Edition by just looking at the overall structure
0:08 of what a Pyramid web application looks like. So, recall we ran the cookiecutter template tool to create this project, and we named it Bill Tracker
0:17 and things like that. Now, let's just look through what was created before we start changing it.
0:23 Over here, you can see that we've got the main project. This is the overall source code for what we're building.
0:29 And in this section we have a bunch of stuff to do with just managing Python Packages. Recall, Pyramid treats its website like a Python Package.
0:38 So, here, for example, you can see the requirements that we're going to have, the name of our package and so on. You don't really have to change this.
0:45 You're not going to publish it to PyPI, things like that. But it is necessary that you run this so that it
0:51 actually scaffolds up and gets your website ready to go. The one thing you probably do need to mess with here is setting dependencies.
1:00 So for example, later we're going to use SQLAlchemy. We need to come back and put SQLAlchemy here. You can either use a requirement.txt file
1:07 or put it in the setup or some combination thereof. On my sites, I actually have requirements.txt files that are much more involved.
1:15 You can use tools like Pyup.io and things like that to manage the requirement's files, but this is also a totally valid way to do it
1:23 and it's necessary to get the thing started. So, there's the stuff we need to run our website as a package.
1:30 That is the output from doing the Python setup.py dev and here's our virtual environment. We may want to go to these in PyCharm
1:38 and just say you know what? Don't try to do any, like, indexing of those files they're not part of the project. So we want to come down here
1:46 and we can see three directories were created. We have static, we have templates, and we have views. And these are sort of our default view.
1:55 Here, it's just going to say here's our main defaul.html. Kind of wish they would name the template similar but there's also a notfound, and notice:
2:03 everything has a __init__. So even the subfile directories here have this __init__, and that's to help treat these folders as subpackages.
2:13 We're going to go over here and we're going to create this view. Let's go ahead and call this just home give it a slightly better name.
2:18 We'll do a little more reorganization in a bit. We have routes. This route here defines the static view of this folder
2:25 so allow files, static files, to be served out of there with 36,000 seconds cache and then it just says we're going to add a route
2:33 to /home, notice there's home and then here we have the route name as home. So that means / maps to this method right here.
2:40 Okay, so that's the views folder. I was kind of new to the template it's really nice that they did that, these templates
2:45 but the template to create the project the cookiecutter template and then we have our templates here. There's an overall layout
2:52 that has the overall look and feel of the site. Here you see what's called a metal slot. This type, here, the metal define slot as content.
3:01 This is a hole in a template that can be reused. So you'll see over here, for example that we're putting stuff into that content slot
3:08 by filling it out here. We're using this overall layout.pt to create a universal look and feel for our site.
3:15 Same thing over here, in the 404, we just say sorry it wasn't found but take the look of the overall site. So that's what's in templates
3:22 and then in static we just have things like the CSS and the various images that are used. Finally, one very important thing is to go
3:29 to the __init__ for the overall package. This is the startup of your web application. So notice over here, calling this main
3:39 want to come here and include the various things that we need, and then we're going to start the web app. Telling it to include the routes
3:46 so if you go over here and look at the routes you can see it takes all the functions called include name
3:51 passes the config to it and runs it, basically. So that's a nice way right here to have it call those. You could also just simply import that file
4:01 and just call those functions, so you know whatever works for you, but that's how they do it so we'll stick with it for this particular application.
4:08 So that's what our web application looks like. We also have tests, we can talk about that later if you want to write tests
4:14 there's some example code in here on how to do that and because I changed this we need to change this back to home.
4:21 That's just to keep it running for you. This one's missing because we didn't install the testing dependencies when we did the setup.
4:27 So here's an overall look at what was created when we ran that cookiecutter template.


Talk Python's Mastodon Michael Kennedy's Mastodon