Difference between revisions of "Getting Started with Google Apps"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (Created page with '=Links= * http://googleappengine.blogspot.com/ * [http://code.google.com/appengine/docs/python/prospectivesearch/ Prospective Search API] * [http://code.google.com/appengine/doc...') |
PeterHarding (talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 6: | Line 6: | ||
* http://code.google.com/appengine/docs/python/tools/uploadinganapp.html | * http://code.google.com/appengine/docs/python/tools/uploadinganapp.html | ||
* http://code.google.com/appengine/docs/whatisgoogleappengine.html | * http://code.google.com/appengine/docs/whatisgoogleappengine.html | ||
* [http://code.google.com/appengine/docs/python/gettingstarted/ Getting Started - Python] | |||
=YAML= | =YAML= | ||
Line 12: | Line 13: | ||
builtins: | builtins: | ||
- datastore_admin: on | - datastore_admin: on | ||
</pre> | |||
=Hello World= | |||
==helloworld.py== | |||
<pre> | |||
#------------------------------------------------------------------------------- | |||
import os | |||
import cgi | |||
import sys | |||
from google.appengine.api import users | |||
from google.appengine.ext import webapp | |||
from google.appengine.ext import db | |||
from google.appengine.ext.webapp import template | |||
from google.appengine.ext.webapp.util import run_wsgi_app | |||
#------------------------------------------------------------------------------- | |||
class Greeting(db.Model): | |||
author = db.UserProperty() | |||
content = db.StringProperty(multiline=True) | |||
date = db.DateTimeProperty(auto_now_add=True) | |||
#------------------------------------------------------------------------------- | |||
class MainPage(webapp.RequestHandler): | |||
def get(self): | |||
greetings_query = Greeting.all().order('-date') | |||
greetings = greetings_query.fetch(10) | |||
if users.get_current_user(): | |||
url = users.create_logout_url(self.request.uri) | |||
url_linktext = 'Logout' | |||
else: | |||
url = users.create_login_url(self.request.uri) | |||
url_linktext = 'Login' | |||
template_values = { | |||
'greetings': greetings, | |||
'url': url, | |||
'url_linktext': url_linktext, | |||
} | |||
sys.stderr.write("[%s]\n" % template_values) | |||
path = os.path.join(os.path.dirname(__file__), 'html', 'index.html') | |||
sys.stderr.write("[%s]\n" % path) | |||
self.response.out.write(template.render(path, template_values)) | |||
#------------------------------------------------------------------------------- | |||
class Guestbook(webapp.RequestHandler): | |||
def post(self): | |||
greeting = Greeting() | |||
if users.get_current_user(): | |||
greeting.author = users.get_current_user() | |||
greeting.content = self.request.get('content') | |||
greeting.put() | |||
self.redirect('/') | |||
#------------------------------------------------------------------------------- | |||
application = webapp.WSGIApplication( | |||
[('/', MainPage), | |||
('/sign', Guestbook)], | |||
debug=True) | |||
#------------------------------------------------------------------------------- | |||
def main(): | |||
run_wsgi_app(application) | |||
#------------------------------------------------------------------------------- | |||
if __name__ == "__main__": | |||
main() | |||
#------------------------------------------------------------------------------- | |||
</pre> | |||
==app.yaml== | |||
<pre> | |||
application: helloworld | |||
version: 1 | |||
runtime: python | |||
api_version: 1 | |||
handlers: | |||
- url: /css | |||
static_dir: css | |||
- url: /.* | |||
script: helloworld.py | |||
</pre> | |||
==index.html== | |||
<pre> | |||
<html> | |||
<head> | |||
<link type="text/css" rel="stylesheet" href="/css/main.css" /> | |||
</head> | |||
<body> | |||
<div class="one"> | |||
<div class="two"> | |||
{% for greeting in greetings %} | |||
{% if greeting.author %} | |||
<b>{{ greeting.author.nickname }}</b> wrote: | |||
{% else %} | |||
An anonymous person wrote: | |||
{% endif %} | |||
<blockquote>{{ greeting.content|escape }}</blockquote> | |||
{% endfor %} | |||
<form action="/sign" method="post"> | |||
<div><textarea name="content" rows="3" cols="60"></textarea></div> | |||
<div><input type="submit" value="Sign Guestbook"></div> | |||
</form> | |||
</div> | |||
<div class="three"> | |||
<a href="{{ url }}">{{ url_linktext }}</a> | |||
</div> | |||
</div> | |||
</body> | |||
</html> | |||
</pre> | |||
==main.css== | |||
<pre> | |||
body { | |||
font-family: Verdana, Helvetica, sans-serif; | |||
background-color: #DDDDDD; | |||
} | |||
.one { | |||
background-color: #BBBBBB; | |||
} | |||
.two { | |||
background-color: #CCCCCC; | |||
} | |||
.three { | |||
background-color: #AAAAAA; | |||
} | |||
</pre> | </pre> | ||
[[Category:InfoInfo]] | [[Category:InfoInfo]] | ||
[[Category:Google Apps]] | [[Category:Google Apps]] |
Latest revision as of 17:35, 9 May 2011
Links
- http://googleappengine.blogspot.com/
- Prospective Search API
- Testbed
- http://code.google.com/appengine/docs/python/tools/uploadinganapp.html
- http://code.google.com/appengine/docs/whatisgoogleappengine.html
- Getting Started - Python
YAML
builtins: - datastore_admin: on
Hello World
helloworld.py
#------------------------------------------------------------------------------- import os import cgi import sys from google.appengine.api import users from google.appengine.ext import webapp from google.appengine.ext import db from google.appengine.ext.webapp import template from google.appengine.ext.webapp.util import run_wsgi_app #------------------------------------------------------------------------------- class Greeting(db.Model): author = db.UserProperty() content = db.StringProperty(multiline=True) date = db.DateTimeProperty(auto_now_add=True) #------------------------------------------------------------------------------- class MainPage(webapp.RequestHandler): def get(self): greetings_query = Greeting.all().order('-date') greetings = greetings_query.fetch(10) if users.get_current_user(): url = users.create_logout_url(self.request.uri) url_linktext = 'Logout' else: url = users.create_login_url(self.request.uri) url_linktext = 'Login' template_values = { 'greetings': greetings, 'url': url, 'url_linktext': url_linktext, } sys.stderr.write("[%s]\n" % template_values) path = os.path.join(os.path.dirname(__file__), 'html', 'index.html') sys.stderr.write("[%s]\n" % path) self.response.out.write(template.render(path, template_values)) #------------------------------------------------------------------------------- class Guestbook(webapp.RequestHandler): def post(self): greeting = Greeting() if users.get_current_user(): greeting.author = users.get_current_user() greeting.content = self.request.get('content') greeting.put() self.redirect('/') #------------------------------------------------------------------------------- application = webapp.WSGIApplication( [('/', MainPage), ('/sign', Guestbook)], debug=True) #------------------------------------------------------------------------------- def main(): run_wsgi_app(application) #------------------------------------------------------------------------------- if __name__ == "__main__": main() #-------------------------------------------------------------------------------
app.yaml
application: helloworld version: 1 runtime: python api_version: 1 handlers: - url: /css static_dir: css - url: /.* script: helloworld.py
index.html
<html> <head> <link type="text/css" rel="stylesheet" href="/css/main.css" /> </head> <body> <div class="one"> <div class="two"> {% for greeting in greetings %} {% if greeting.author %} <b>{{ greeting.author.nickname }}</b> wrote: {% else %} An anonymous person wrote: {% endif %} <blockquote>{{ greeting.content|escape }}</blockquote> {% endfor %} <form action="/sign" method="post"> <div><textarea name="content" rows="3" cols="60"></textarea></div> <div><input type="submit" value="Sign Guestbook"></div> </form> </div> <div class="three"> <a href="{{ url }}">{{ url_linktext }}</a> </div> </div> </body> </html>
main.css
body { font-family: Verdana, Helvetica, sans-serif; background-color: #DDDDDD; } .one { background-color: #BBBBBB; } .two { background-color: #CCCCCC; } .three { background-color: #AAAAAA; }