Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Routing and URLs
Lecture: Account routes and views

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The last thing we're going to do is we're going to have the ability to login and out and basically manage accounts.
0:06 You've noticed, I've already created that part there. Let's go and add the routes for that and we'll figure out what we need.
0:13 So, here we'll say account_controller just for time sake, let me just drop those in there. We're going to have /account, account_login
0:25 account_register and account_logout. Go over here. I'll implement those real quick and we'll come back to it.
0:33 OK, I've just dropped in a few of the things that we're going to need that correspond to account account_login, account_register, account_logout.
0:41 Over here we've got, here's just going to be /account this is going to be you're home, and notice, in this one
0:48 I'm explicitly setting the request method. I really only want this to respond to GET and this one, actually, it doesn't matter so much
0:55 but down here it definitely does. So, here's the login that's going to use the template login which I've created over here
1:03 and this one responds only to GET. This is going to show the form whereas this one is going to process the login when you submit it as an HTTP POST.
1:12 So we'll set the name, because we can't have two functions with the same name so we're going to have to name the route there.
1:21 With registration, same thing, register_get, register_post and finally just to logout. So that rounds out all the URL's
1:29 that are going to be at play here. Let's run this, and just double check. So, let's go over here to /account/login
1:41 All right, looks like the account stuffs working. Trust me, I think the rest is going to be just fine as well.
1:47 That was a lot of juggling of various pieces and I find that to be one of the things that can be tricky routing, because we've got these view methods
1:56 that are contained within the controllers. The controllers then link, you know leverage these templates
2:03 and the templates are then laid out in a certain way. Pretty straight forward. What we've done is we've registered our core home routes
2:10 the various ones to do with packages that we put in to the PackagesController the one to do with accounts put them in the AccountController
2:17 and then finally, we run scan and it just goes through every file looking for @view_config decorators and then lines them up.
2:24 We saw that if they don't match there's going to be an error.

Talk Python's Mastodon Michael Kennedy's Mastodon