[TOC]
- Sign up for Google App Engine (gmail + SMS verification)
- Login and create an Application (e.g. named john-pfeiffer reachable at http://john-pfeiffer.appspot.com )
- Download and extract the SDK (e.g. gae-python.zip)
- cd google_appengine
cp -a new_project_template helloworld
nano helloworld/app.yaml
application: john-pfeiffer
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
nano helloworld/main.py
#!/usr/bin/env python
import webapp2
class MainHandler( webapp2.RequestHandler ):
def get( self ):
self.response.write( 'Hi World!' )
app = webapp2.WSGIApplication( [
( '/' , MainHandler )
], debug=True )
VIEW THE APP ON YOUR LOCAL MACHINE
./dev_appserver.py helloworld
INFO 2012-12-27 04:20:20,399 dev_appserver_multiprocess.py:655] Running application dev~john-pfeiffer on port 8080: http://localhost:8080
INFO 2012-12-27 04:20:20,399 dev_appserver_multiprocess.py:657] Admin console is available at: http://localhost:8080/_ah/admin
UPLOAD THE APP TO GOOGLE APP ENGINE
./appcfg.py update helloworld/
07:44 PM Host: appengine.google.com
07:44 PM Application: john-pfeiffer; version: 1
07:44 PM
Starting update of app: john-pfeiffer, version: 1
07:44 PM Getting current resource limits.
07:44 PM Scanning files on local disk.
07:44 PM Cloning 1 static file.
07:44 PM Cloning 3 application files.
07:44 PM Uploading 1 files and blobs.
07:44 PM Uploaded 1 files and blobs
07:44 PM Compilation starting.
07:44 PM Compilation completed.
07:44 PM Starting deployment.
07:45 PM Checking if deployment succeeded.
07:45 PM Will check again in 1 seconds.
07:45 PM Checking if deployment succeeded.
07:45 PM Will check again in 2 seconds.
07:45 PM Checking if deployment succeeded.
07:45 PM Deployment successful.
http://john-pfeiffer.appspot.com
appcfg.py download_app -A <your_app_id> -V <your_app_version> <output-dir>
app.yaml
application: john-pfeiffer
version: 6
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #!/usr/bin/env python
import webapp2
class MainHandler( webapp2.RequestHandler ):
def get( self ):
self.response.write( 'hello John Pfeiffer!' )
class PageOne( webapp2.RequestHandler ):
def get( self ):
self.response.write( """
<html>
<body>
PageOne <br />
<form action="/page-two" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit"></div>
</form>
</body>
</html>
""");
class PageTwo( webapp2.RequestHandler ):
def get( self ):
self.response.write( 'PageTwo' )
def post( self ):
get_values = self.request.GET
post_values = self.request.POST
self.response.write( str( get_values ) + "<br />\n")
self.response.write( str( post_values ) )
app = webapp2.WSGIApplication([
('/', MainHandler),
('/page-one', PageOne),
('/page-two', PageTwo)
], debug=True)
def main():
run_wsgi_app( application )
if __name__ == "__main__":
main()
|
UPDATING THE APP
./appcfg.py update john-pfeiffer
update does not publish the new version yet
./appcfg.py set_default_version john-pfeiffer
or you can use the WebUI dashboard to change the default or delete a Version for an Application Instance
python appcfg.py --no_cookies update /path/to/application-directory (contains app.yaml)
this allows you to use a different google account
REDIRECTION
# -*- coding: utf-8 -*-
import webapp2
class MainHandler( webapp2.RequestHandler ):
def foo( self ):
self.redirect( 'https://john-pfeiffer.appspot.com/search' )
./dev_appserver --host=0.0.0.0 --port=8888 --admin_host=0.0.0.0 --admin_port=8889
allow all network access to app on 8888 and admin ui access on 8889