Hi I'm Brett Slatkin, a software engineer on the
Google App Engine team.
App Engine enables editors to build web applications on
Google's infrastructure.
I'm here today to show you how to quickly build a guest book
application using App Engine. Let's get started.
First we'll create a directory for my new application and
bring it into my editor.
Then I'll create an "app.yamo" file with my
application configuration.
I'll type my application name.
Version of this application, in this case
the first version.
Version of the apis I'm going to be using.
And the runtime, which is "python."
Then I declare how my URL is going to map
to my application.
In this case, I'm going to have all URLs go to single
python scripts called "main."
I'll create my main python file.
I'll type in a very basic, "Hello world" application.
Now I'll go to the terminal and start the
development web server.
And now that the server is running, I can go and view the
"Hello World" application.
Now let's do something more complicated and build
a web application.
To do this we've provided a very basic web application
framework called "Web App."
I'll import the "Web App" module and then define a
handler, which will handle the requests from
the application.
The methods of this class will handle HTP requests.
In this case, I just want to handle a get request, and I'll
print out a "Hello World" message.
Text "schema handler " I'll use "wsgiref," which is
python standard web application container.
And I'll define a "WSGIApplication" throughout
all URL's access to my really basic handler.
And of course, tell phython to run my main function.
Now let's view this in our browser.
Great. It showed up and it's working.
Now let's do some templates to make this page look better.
We provide a basic library for doing this.
Let's create a template file using Django templates.
To begin with, I'll just have some HTML that says,
"Hello World."
I'll import our template module.
And then render the template.
And then I can view this in my browser.
Now let's implement a basic UI for our web application.
I'll go back into my template file and start writing my
UI and HTML. So first I'll have a form.
In this case, I want to post.
And the form will have a couple of fields.
Since it's a guest book, let's start off with the message
I want to have.
In this case, it's just text fields with "message."
And we'll change the "submit" button to say "shout."
And now we can go back and view this in our browser.
So let's have our web application handle the post
request and then do something more interesting.
I'll modify "MyHandler" to handle post requests, as well
as the "get" requests.
Now let's hook this up to the data store.
To use the data store, I'll import the dv module and to
find a model class that says what fields will have to store
in the data store.
In this case, my model class will be called "Shout."
And I'll have two fields. First, the message.
And then the time the message was left.
Now, in the post method, I'll use the request parameters to
create a new "Shout" and put it in the data store.
Then I'll redirect the user back to the main page.
Then I can go back to my browser and see this is
working right now.
Now we're handling posts and putting posts and putting data
in the data store, but we're no retrieving it.
So let's create a query to get the data back out and
present it to the user.
To do this I'll create a "GqlQuery."
And then I'll use the results of the query to
populate my templates.
And passes values into the template renderer.
Then if I go into my template, I can use the results of the
query and render them to the user.
In this case, I'm using Django templates.
Now I can go back to my browser and see this is
immediately working.
And there are my two requests from before.
Now I can type of few more messages.
You'll see they are not in any particular order.
So I'd like to add a sort order to my query.
New messages go to the top.
I'll modify my model to have another property,
which is "who set the message?"
In this case, it's optional because some of the messages
were sent without an explicit sender.
Then I'm going to go to my template and add
that new field.
It would also be good to have labels on these input fields.
Then I need to make sure that when I create my shot I've
correctly populated the "who" field.
I'd also like to render who sent each message.
So, I'll go back to my template and add that too.
In the case the "who" field is empty, I'll just say
it's from anonymous.
Now let's go back to the browser and see what
this looks like.
You can see all the messages are from anonymous because
none of them has a sender.
Let's add a new one with a sender for me.
You'll see my name has appeared.
One last thing I'm going to do is fix the title to point out
this is my application called "shoutout!"
For this application, I'll use the App Config Tool.
I'll just type, "appcfig update" to deploy my
application and then the naming application directory.
And we're done.
Now I can access this application on appspot.com.
Now let's leave a message.
That's it. We built an application and deployed it.
We hope that you check out Google App Engine.
We look forward to hearing your comments.
If you'd like to learn more about App Engine, please join
us at Google IO, Google's developer event on
May 28th and 29th.
Thanks for watching.