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


Talk Python's Mastodon Michael Kennedy's Mastodon