#100DaysOfWeb in Python Transcripts
Chapter: Days 37-40: Introduction to Pyramid framework
Lecture: Home page (fake data)

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now we got the structure of our site in place.
0:02 Let's go right some code and start making it do web things.
0:05 Over here, this is the function that's called
0:08 when we just go to /.
0:11 When we go to whatever the URL is
0:13 /, right there. See this bill tracker pro
0:18 is that passed right there.
0:19 So, if we change that to demo, when you rerun it
0:24 you see, that's the data being passed over and shown there.
0:27 Let's first look and see how that's happening.
0:29 So, we've wired up, this render, this Chameleon template
0:34 to this method, and then we're returning a dictionary.
0:37 So the idea is we're going to take and write whatever code
0:43 we have to write here to access the database
0:45 talk to a web service, look at the cookies
0:47 you know whatever you're going to do for your logic
0:49 to generate a dictionary, a model
0:51 that's going to be passed over to that template.
0:54 So, let's go look at that template here.
0:57 In the model, in the dictionary
0:59 we have a thing called project.
1:01 And it has this value.
1:03 What we wanted to do, or what our little template
1:05 wanted to do was say, welcome to the such and such project.
1:08 So here you can see we have ${}
1:11 and then the name of that value and the model.
1:14 Not dictionary access, just straight up, the name project.
1:18 So, we have project there, and we have project there.
1:21 So, basically, our goal to create this web app
1:23 is going to be to talk to the database
1:26 figure out what interesting data we want to pass
1:29 and then pass it over here.
1:31 Let's look a little more here.
1:33 So let's suppose we have items
1:36 something like that, we'll just make this up real quick.
1:37 And we'll put some kind of lists, this will be item one
1:42 item two, looks like I forgot a comma
1:45 we'll have item1, item2, item3, and item4.
1:51 So, we're going to be working with particular user
1:53 and when we go to that user's set of bills that they have
1:57 we want to show those. Let's just demonstrate how we might work with this data
2:01 over here as well. One thing you'll notice about Chameleon
2:04 is it's a super clean language.
2:06 And I'll show you some, call out examples
2:09 at the end of this demo.
2:10 But you'll see it build up over time.
2:12 A lot of these template languages, you'll do things like
2:15 $% for thing in that collection
2:20 and then you'll put a bunch of HTML
2:22 and then down here you'll say percent, end for percent
2:28 and you just want to say that, right?
2:30 Sometimes there's just so much structure
2:32 around these things, like Jinja2 and what not.
2:36 How does it work here?
2:37 Let's go down here, and we're going to have your items.
2:41 Little paragraph.
2:42 And we want to create an unordered list
2:46 and we'd like a list item in it
2:47 we can do a little expand-o like that, ul angle bracket li
2:52 so we want to have one of these for every item.
2:55 Check this out.
2:56 So we come over here on this thing called the TAL
2:58 Template Attribute Language, and we can say repeat.
3:02 This is more like the JavaScript front-end style
3:04 programming, say like AngularJS or something
3:06 more than it is like Jinja.
3:08 We're going to come over here, and we're going to say
3:10 i items, I wish it was i in items, but it's just i
3:14 the in is silent I guess.
3:17 We can just come down here
3:19 and we even have this be an ordered list if we want.
3:22 Come over here, and we'll do this little $
3:24 to say the value, and we'll put the i there.
3:28 Even mix it in like that, let's say.
3:30 If we rerun that, and we go reload it, by clicking on it
3:34 'cause I closed Firefox you can see here we have our items
3:37 item1 is an item, item2 is an item, and so on.
3:40 We have our ordered list of those items.
3:43 Honestly, there is not a lot more to it than that.
3:45 We're going to go to our database, which we haven't done yet.
3:48 We're going to get our data, get it into the form
3:50 of some kind of model that we can pass across
3:53 and then we're just going to loop across it
3:55 using this template attribute language.
3:57 That's our little test version.
3:59 And the next thing we're going to do is
4:01 we're going to actually use the real database data
4:03 to render it.