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

Talk Python's Mastodon Michael Kennedy's Mastodon