Python for Entrepreneurs Transcripts
Chapter: Build web apps with Pyramid: Applied web development
Lecture: Concept: Mapping routes to controller actions
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Let's review some of the options we have for mapping action methods on controllers.
0:07
So here you can see we have a HomeController, it has a pyramid_handlers.action decorator on an index.
0:15
Now, this one allows... this particular action method is actually processing a form post on the home page.
0:24
So if maybe on your homepage you put a form that has a place for like an email address and a button that says "hey, sign up for my newsletter",
0:32
this would receive the email address and actually put them in your newsletter, there is very likely a corresponding GET version that shows the homepage
0:40
and that form and so on. So over here you can see that we can set the renderer, this is probably something you are going to do almost all the time,
0:48
you want to pick some kind of file convention I've shown you my templates/controller name
0:53
directory/action name file convention and that works very well for me, so we are going to specify this here and then notice,
1:01
we are actually setting the request method, so this method will only be called if there is an HTTP post to that URL that we've mapped it to,
1:09
if there is a GET, there is some other not-shown method that is run, so here we can filter by request method,
1:15
in Python you can't have method overloading by parameter, there is only one method with the given name in any given class
1:23
or outside of any given class in a particular module. So we can't have like index and then have some parameters
1:30
and then an index and a get, so here we are actually setting the name to allow us to have an index_post and an index_get.