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