Now let's go back to our editor and turn
this into a mini shopping list application. Okay we're going to
add a bunch of code here that I'll walk
you through as I go. Okay first thing I'm going to
do is replace this input type hidden line with
a percent s and if you recall percent s is
the. Python string formatting character I'm going to give you
a quick example of that. I'm in Python real quick,
if we have a string you know, hello percent S. And I say percent Steve
it substitutes the string following the percent sign in to the percent S in the
string. So if I were to say greeting, equals hello percent S, and I can
say greeting [UNKNOWN] it substitutes that string
in. So, anyway just kind of basic Python,
but I just wanted to make sure you understand it, because I'm
going to abuse it in this lesson. Okay, so a replaces input with percent
S, and I'm going to add a couple more templates here and then
explain things as I go. Okay, and now I'm going to add a couple
more strings, HTML strings and I'll explain them as I go. What
I'm trying to do here is trying to make a big mess here
for you that we will clean up using templates later. Okay, again
I'm making, I'm using another triple coded string so I can enter HTML
[SOUND] I'm going to make my input type equals
hidden. Name equals food again. And value equals
percent S, because I'm going to substitute more values
in here. Then I'm going to make one final string
that will represent a shopping list. A couple
blank lines, a little title, and then an unordered
list. Remember the UL tag makes an unordered
list. I'm going to use percent S to represent our
content inside there. And them I'm going to close my
unordered list tag. Now you'll notice I'm not really
indenting things or not getting any nice syntax highlighting.
That's because I'm editing strings in Python. It's not an
ideal way to go but, it's what we're doing
for now. Okay, now let's update our main page handler
to do more than just print out the form
HTML. What? Actually, let's take a look at what happens
if, if I just print out this HTML as it is.
"Kay, we're back in our browser, and I've rerouted the page, and
now you can see there's this big ugly percent S in
the middle of our form. And remember, this is in the HTML,
this is where our hidden element used to be. If I
were to look at the source of this page, you can see
it right here in the browser that ugly percent S. So,
anyway, let's go back to updating our code. First thing, I am
going to do is build up a string called output. It's going to be,
it's going to start off as our form HTML and this is what
we are going to return to the user. So, go ahead and, and
update this to return output. Okay, and now remember our, form HTML has
a percent S variable in it so I'm going to make a holding
place for the value I'm going to in there, and I'm going to call
that hidden HTML, and that will refer to that'll hold the content
that we're going to sub into there, that'll be where our hidden inputs go.
'Kay, now this line here gets all of
the get parameters, or post parameters for that
matter, called food. get_all basically means in, in
App Engine, basically says, if there are multiple parameters
with the same name, get all of them, and put them in a list. So items
will be a list of all the food parameters that are in the URL. 'Kay, now we're
going to loop overall each of those items. So, the first
thing we're going to do is we're going to add our hidden
HTML line. Okay, and actually I have a little bug
here. I am going to replace, I going to rename hidden HTML to
be output hidden. I'm going to prefix all of my strings
that are holding output HTML with the word output. And because
I originally called that hidden HTML but we're already using
that up here to refer to this little HTML string for
hidden input. So, for each item in items
add to the string hidden HTML substituting the
food name. So basically output hidden will be
a bunch of input type hiddens where the value
is the food from the URL. Okay, I'm
going to add another [UNKNOWN] here we'll call output
items, [SOUND] and also for each item and
items, we're going to append another little bit of HTML.
And you can see actually I didn't create item HTML,
let's add that real quick up here after our hidden
HTML. And this will be a list item that goes
inside the shopping list HTML. So we're going to create up,
add up a bunch of those. So we've got output_hidden
which will be a bunch of hidden inputs and output_items
will be a bunch of list elements. Okay, now we're
going to use our shopping list HTML equals shopping list HTML substituting
in our items and then our output. And then to
the end of our output we're going to add our shopping
list. And we will only want to add things for
our shopping list if they were actual items in the response.
So if the response is empty, none of this is
going to work. So let's make sure we do this properly. So
I indented everything. As you can tell, this is getting
somewhat hard to read. That's kind of the point. And finally
we're going to take our overall output and substitute in the, the hidden
string that we've been building up here. Now, when of all this is
said and done, this is going to give us a basic shopping list
functionality. Which I'll demo now, and then we'll walk through the actual code.