RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Web application building blocks
Lecture: Pyramid building block: Models

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Because Pyramid is effectively a model view controller type of architecture models obviously play a very important role,
0:09 so the idea is we set up our routes, the request comes into our views, our view method here called index, and then we need to do some processing
0:17 and return some data back, basically to a renderer but the idea is to return it back to the user with some kind of transformation.
0:26 So in this case, you can see I have set the renderer to xml so what is passed here is theoretically going to be translated
0:32 magically in some way, into xml. Now, the thing that we return from these methods either has to be a raw response object which we create
0:41 or it has to be a dictionary list, list of dictionaries and fundamental types, right, so here we have an album, we saw just like before
0:51 we're going to return the json object or a dictionary rather which is going to be translated often to json, in this case to xml,
0:57 and it's going to have one top level node called albums and then in there a bunch of subnodes represented
1:05 by each individual album, has preview, title, url. So you'll find in almost every view method that you create
1:12 it's either going to return a model or some kind of redirect result but most of the time, things are going good, you're going to be returning models.


Talk Python's Mastodon Michael Kennedy's Mastodon