Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Routing and URLs
Lecture: Adding the package-details route
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
The last thing to do, let's extend this let's have, I'm just going to copy and paste it'll be a little quicker
0:07
I'm going to call this AccountController. And PyCharm asks, can we add this to Git I'm going to just say yes you can.
0:16
So we go over to our AccountController I'm going to get rid of most of this. The name has to be changed, so let's just comment this out for a second.
0:24
But just so we have the pieces in place and we'll do the same thing for packages. Packages, we're going to write some bits here.
0:33
OK, so for packages, remember what were looking for, is we're looking for /project that's the way it works. Let's just remind ourselves.
0:43
PyPI.org, if we go over to any particular project and we click on this, notice the url is /project/the name of the package with a /.
0:55
Okay, so that's what we're aiming for something like that. And let's put a little project, package name bit in there.
1:08
So this is the route that we're looking for. And let's call that package_details. And this is going to be packages not index, how about details?
1:25
For now, let's just return no data. We'll return the package name in just a minute. Okay, great, this is looking a little broken
1:36
but it's actually not broken that's just PyCharm not quite refreshing itself correctly. So we've got our home, it says home
1:43
let's just call this details. It's going to be contained in the packages so it'll be packages.details, that's
1:49
we don't really need, since we've broken this up into the modules by category we don't need to put them on the method names. So we need to add this.
1:58
If we try to run this now and we refresh, well, actually, it doesn't even run. Didn't make it that far. If we come over here and we look
2:08
you'll see, no route named package_details found in view registration. Alright, so the next thing to do is going to be go fix that.
2:17
So that brings us back to this method we were working on before. So we've got our stuff to do with home_controller
2:25
maybe, we'll put it like that, I don't know. Over here we'll have packages or PackageController. And we're just going to do the same thing.
2:33
config.add_route and we're going to give it a name. What'll we call it, project_details, I think? Let's look, no, package_details.
2:43
So we'll say package_details and the url is actually going to be /project / whatever the name is. Now, something that's a little bit annoying
2:55
with Pyramid routes is whether that's there or not makes a big difference. And if you want to let them put it there
3:01
or not put it there, it's not a great option. So what we can do is, like have two routes, one with a / and one without a /, it's okay.
3:11
It's not great, but it'll do. So if we come over here, for that to work we're going to have to have both routes here.
3:21
So let's rerun this, and it should just say the details is not found, so we'll fix that next. But let's see that we can get a little farther
3:28
what we did, it ran, that's good. If we refresh it, we come over here to /project/requests. Great, details wasn't found.
3:39
So the next thing we have to do is just put the details in there, easy enough. So let's go down here and what's a great example?
3:48
Let's take about is pretty simple. Let's paste that as details just copied and pasted in PyCharm. We'll go over here and we'll have package
3:58
and I'm just going to put the name, package name. We'll figure out the details when we get to the data access section
4:13
but let's just work on the route to make sure this is loading the correct one, okay?