#100DaysOfWeb in Python Transcripts
Chapter: Days 37-40: Introduction to Pyramid framework
Lecture: Reorganizing our app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now that you're familiar with
0:01 what you get when we actually created a project
0:03 using the cookiecutter template
0:05 let's make it a little bit better.
0:06 There's a few things that I really don't love about this.
0:09 Although, they're doing a better job of organizing it
0:11 within the latest cookiecutter template
0:13 it still could use a little bit of help.
0:15 This static folder in a real web application
0:17 will have tens, maybe hundreds of images
0:21 many different JavaScript files, CSS files, and so on
0:24 and just blasting them in here
0:26 Eh, its kind of yuck.
0:27 So let's go and create some directories here.
0:29 So let's call one for image, we'll call one css
0:34 and we'll call one js, for JavaScript.
0:37 Now I'm just hitting Command + N to get that new menu.
0:39 You can, of course right click.
0:40 So we'll come over here
0:41 and we'll drop these into their place.
0:43 We'll end up not using those too much, but that's fine.
0:46 The other thing is we have this Bootstrap theme
0:49 that's got, you know, plenty of stuff in here.
0:52 I don't really want to mess with it or Bootstrap
0:54 so let's go over here
0:55 and add another style sheet called site.css.
0:59 So this is where we're going to put our various bits
1:02 of additional CSS to do our design.
1:06 We're not going to have any JavaScript right now
1:08 and, well we will have some images
1:10 but we don't have them yet
1:12 and we'll get to that design side of things soon.
1:14 Okay, so that's all well and good.
1:15 We're going to need to adjust our template over here
1:19 to make that work.
1:20 So if you notice, it says we have
1:22 this static site, static URL
1:25 to the package name and this
1:26 and then of course, this should be /img
1:29 but I personally am not a huge fan of this if that
1:32 for some reason, that file's not there
1:34 this ends up with like a runtime crash
1:36 so I'm just going to put, you know, standard
1:38 old, traditional URL here.
1:41 And if you notice, if I go over here
1:43 and I type this, we get auto-complete.
1:47 So, that's pretty cool that we can do auto-complete there
1:49 and that's because we marked this as a resource root.
1:53 Okay, so let me just go through really quickly
1:55 and fix all the other pieces.
1:56 So here, this goes to static, and then we have /img.
2:00 This is okay, this is external.
2:02 This CSS file moved into the css folder.
2:06 Those are good. This moved into the image.
2:10 Everything else is coming off of a CDN.
2:12 So, oh, wait, this part, I got to fix.
2:16 There we go.
2:17 Alright, let's try to run this really quick as we're going
2:19 just to make sure everything still looks the same.
2:21 It should. Yep, still looks great.
2:24 The other thing that we want to do
2:26 is up here where we're including this theme
2:28 we also want to include our site.css
2:31 after our theme so we can override settings.
2:33 There's no values in there
2:34 so nothing super impressive is going to happen.
2:36 But there we have that, that layout fixed
2:38 so we're using these pieces.
2:40 We can close those bits up.
2:43 The other thing that I'm not a huge fan of
2:46 is having all the templates piled in here.
2:48 Exact same story. You can have hundreds
2:50 of templates in a large web application.
2:52 Do you want to just pile them in here?
2:54 Probably not.
2:55 So let's go over here and make a few fixes.
2:58 We have errors, maybe 404 or 500
3:01 permission denied, et cetera.
3:03 We're going to have home
3:04 so maybe put the stuff for our default layout there
3:08 and then importantly we'll have a shared section.
3:11 Let's put this one into shared, put this one into home.
3:15 We'll have more of course, put that one into errors.
3:17 And this one, let's rename it, mytemplate.
3:20 Does that tell you anything about it being home?
3:22 No, it does not.
3:24 So let's go over here and just call this default
3:26 is what they called the view, so let's call it that as well.
3:31 Now if we go to these last things we got to change
3:33 this is going to be ../, whoops.
3:36 ../shared, like that.
3:39 Going in error, in your error page too.
3:41 Alright, does it still work?
3:43 It does not because its already running
3:45 we got to click this used shared instance only
3:48 Restart it, now it'll work, _default.
3:53 Is that what I called it?
3:54 Where is it getting called that?
3:56 That is being called, up here in the view.
4:00 I'll make that default
4:02 and this of course needs to be /home.
4:04 There we go, now it should work. Perfect.
4:07 All that work and we're back to what?
4:09 Where we were, of course.
4:10 But, the benefit is, we have a structure
4:12 that is much more ready to be a real
4:14 full-blown web application and we're going to add a lot to it.
4:17 Okay, I think this reorganization is good.
4:20 And that might have seemed like a lot at first
4:22 when you're just getting started with Pyramid
4:24 but I think you'll find it is really going to pay off
4:26 as we build out this app.