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
0:05 models obviously play a very important role,
0:08 so the idea is we set up our routes, the request comes into our views,
0:12 our view method here called index, and then we need to do some processing
0:16 and return some data back, basically to a renderer
0:19 but the idea is to return it back to the user
0:22 with some kind of transformation.
0:25 So in this case, you can see I have set the renderer to xml
0:28 so what is passed here is theoretically going to be translated
0:31 magically in some way, into xml.
0:34 Now, the thing that we return from these methods
0:37 either has to be a raw response object which we create
0:40 or it has to be a dictionary list, list of dictionaries and fundamental types,
0:45 right, so here we have an album, we saw just like before
0:50 we're going to return the json object or a dictionary rather
0:53 which is going to be translated often to json, in this case to xml,
0:56 and it's going to have one top level node called albums
0:59 and then in there a bunch of subnodes represented
1:04 by each individual album, has preview, title, url.
1:08 So you'll find in almost every view method that you create
1:11 it's either going to return a model or some kind of redirect result
1:16 but most of the time, things are going good, you're going to be returning models.