Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Your first Pyramid site
Lecture: Project structure
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Let's take a quick tour of the directory structure, or the file structure that we have for our pyramid project
0:05
so you can see what, how they've organized it and what all the pieces mean. Regardless whether you've created this in PyCharm
0:13
or you've created it using Cookiecutter on the Command line you'll get the same basic output. So over here, we'll have our directory
0:21
here it's called make_your_project. This is basically the top level package that represents our website. So in here we have a static directory.
0:29
This is where CSS, JavaScript, and Images go. You don't have to drop them all flat in there, right? That's how the templates work
0:38
but I would create a css folder, an images folder a javascript folder, maybe even more than that. So any, sort of, directory structure
0:45
you want to create underneath there, it's totally fine. Then the dynamic HTML templates live in templates. And PyCharm colors them purple
0:53
but there's nothing really special about that directory. When our app starts up it's going to run this __init__.py
1:01
and there's a main method in there that gets executed. So that is the entry point for your app that's where all the initial setup goes
1:09
where we register the route and maybe we read the database configuration and get it all set up, things like that.
1:16
We're going to talk about how to test your web applications and one of the real big advantages of Pyramid is it's super, super testable.
1:23
We'll talk about how to do that and it's really, really nice. And finally, where your views or controller methods go
1:31
this is right now, a single views.py file. That might be okay for a really simple app but in practice, we'll want more organization for our tests
1:41
and more organization for our views, even templates. So, consider this the starting point but as we build this up, I'll show you ways
1:49
where you'll probably want to reorganize things as if you know, if this is going to be a real major application.
1:56
That's how it starts out, just a test file and a view file. Now, this .egg_info thing, this is an artifact from running Python setup.py develop
2:07
and it's needed for Python to do its magic but you can just ignore it, okay? So it's going to be there, but just ignore it
2:13
it's part of the register of this package for development mode. We have our two project settings and configuration files.
2:22
We've gone over this a few times but development.ini, that's what you want for dev production for production, probably, things like that.
2:29
And that's really all you need to mess with. Maybe setup.py, maybe? If you're going to add a dependency or something like that in there
2:35
but this is a starting place. So you know how and where to go look for what you need. Typically you're going to be in __init__.py
2:42
in views, in templates, dropping stuff into static.