class: split-30 nopadding background-image: url(https://cloud.githubusercontent.com/assets/4231611/11257863/47c745ae-8e87-11e5-9753-9d4a321766b6.jpg) .column_t2.center[.vmiddle[ .fgtransparent[ #
] ]] .column_t2[.vmiddle.nopadding[ .shadelight[.boxtitle1[ # GAE - Python ### [Eueung Mulyana](https://github.com/eueung) ### http://eueung.github.io/EL6240/gae #### Python CodeLabs | [Attribution-ShareAlike CC BY-SA](https://creativecommons.org/licenses/by-sa/4.0/) #### ]] ]] --- class: column_t1 middle .fonth2[ .tab1.fullwidth[ | Agenda | |:-------------:| | GAE Basics | | Example - Guestbook | ]] --- class: split-30 nopadding background-image: url(https://cloud.githubusercontent.com/assets/4231611/11257863/47c745ae-8e87-11e5-9753-9d4a321766b6.jpg) .column_t2.center[.vmiddle[ .fgtransparent[ #
] ]] .column_t2[.vmiddle.nopadding[ .shadelight[.boxtitle1[ # GAE Python Basics #### ]] ]] --- class: split-50 nopadding .column_t2[.vmiddle[ ## Getting Started #### .figstyle1[  ] .center[GAE Launcher : Add New Application] ]] .column_t1[.vmiddle[ .figstyle1[  ] .figstyle1[  ] .center[GAE Launcher - Idle vs. Running App] ]] --- class: split-50 nopadding .column_t1[.vmiddle[ .figstyle1[  ] .center[GAE Launcher -> Browse] ]] .column_t2[.vmiddle[ .figstyle1[  ] .center[GAE Launcher -> SDK Console] ]] --- class: split-50 nopadding .column_t2[.vmiddle[ ``` import webapp2 #---------------------------------------- class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello world!') #---------------------------------------- app = webapp2.WSGIApplication([ ('/', MainHandler) ], debug=True) ``` .figstyle1[  ] ]] .column_t1[.vmiddle[ ## Generated Structure/Codes ```yaml application: hello 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" ``` .center[app.yaml] ]] --- class: column_t2 middle center .figstyle1[  ] ### https://console.cloud.google.com -> Create Project --- class: column_t1 middle center .figstyle1[  ] ### https://console.cloud.google.com/home/dashboard --- class: column_t2 middle center .figstyle1[  ] ### GAE Launcher -> Dashboard --- class: split-50 nopadding .column_t1[.vmiddle[ ## Uploading #### .figstyle1[  ] .center[GAE Launcher -> Deploy] ]] .column_t2[.vmiddle[ ```yaml *application: hello-gae-1156 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" ``` .center[app.yaml] ]] --- class: column_t2 middle center .figstyle1[  ] ### Deployed | GAE Launcher -> Dashboard --- class: column_t1 middle center .figstyle1[  ] ### Live - http://hello-gae-1156.appspot.com --- class: split-30 nopadding background-image: url(https://cloud.githubusercontent.com/assets/4231611/11257863/47c745ae-8e87-11e5-9753-9d4a321766b6.jpg) .column_t2.center[.vmiddle[ .fgtransparent[ #
] ]] .column_t2[.vmiddle.nopadding[ .shadelight[.boxtitle1[ # Example - Guestbook #### ]] ]] --- class: split-50 nopadding .column_t2[.vmiddle[ ## A (Minimal) Guestbook ```html *An anonymous person wrote:
test dua dua dua dua dua
An anonymous person wrote:
test satu
*
*
``` .center[source] ]] .column_t1[.vmiddle[ .figstyle1[  ] .figstyle1[  ] .center[Local] ]] --- class: column_t1 middle center .figstyle1[  ] ### Admin | GAE Launcher -> SDK Console --- class: column_t2 middle center .figstyle1[  ] ### Admin | GAE Launcher -> SDK Console --- class: split-50 nopadding .column_t1[.vmiddle[ ### guestbook.py ``` import cgi import datetime import webapp2 #--------------------------------------- from google.appengine.ext import ndb from google.appengine.api import users #--------------------------------------- guestbook_key = ndb.Key('Guestbook', 'default_guestbook') #--------------------------------------- *class Greeting(ndb.Model): author = ndb.UserProperty() content = ndb.TextProperty() date = ndb.DateTimeProperty(auto_now_add=True) #--------------------------------------- *class Guestbook(webapp2.RequestHandler): def post(self): greeting = Greeting(parent=guestbook_key) if users.get_current_user(): greeting.author = users.get_current_user() greeting.content = self.request.get('content') greeting.put() self.redirect('/') ``` ]] .column_t2[.vmiddle[ ``` *class MainPage(webapp2.RequestHandler): def get(self): self.response.out.write('') #--------------------------------------- greetings = ndb.gql('SELECT * ' 'FROM Greeting ' 'WHERE ANCESTOR IS :1 ' 'ORDER BY date DESC LIMIT 10', guestbook_key) #--------------------------------------- for greeting in greetings: if greeting.author: self.response.out.write('
%s
wrote:' % greeting.author.nickname()) else: self.response.out.write('An anonymous person wrote:') self.response.out.write('
%s
' % cgi.escape(greeting.content)) #--------------------------------------- self.response.out.write("""
""") #--------------------------------------- *app = webapp2.WSGIApplication([ * ('/', MainPage), * ('/sign', Guestbook) *], debug=True) ``` ]] --- class: split-50 nopadding .column_t2[.vmiddle[ ```yaml *application: guestbook-test-1156 version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: .* * script: guestbook.app libraries: - name: webapp2 version: "2.5.2" ``` ]] .column_t1[.vmiddle[ ### app.yaml ]] --- class: column_t1 middle center .figstyle1[  ] ### Live --- class: column_t2 middle center .figstyle1[  ] ### Dashboard --- # References 1. [Hello, World! in 5 minutes - Python — Google Cloud Platform](https://cloud.google.com/appengine/docs/python/) 1. [Introduction - Python — Google Cloud Platform](https://cloud.google.com/appengine/docs/python/gettingstartedpython27/introduction) --- class: split-30 nopadding background-image: url(https://cloud.githubusercontent.com/assets/4231611/11257863/47c745ae-8e87-11e5-9753-9d4a321766b6.jpg) .column_t2.center[.vmiddle[ .fgtransparent[ #
] ]] .column_t2[.vmiddle.nopadding[ .shadelight[.boxtitle1[ # END ### [Eueung Mulyana](https://github.com/eueung) ### http://eueung.github.io/EL6240/gae #### Python CodeLabs | [Attribution-ShareAlike CC BY-SA](https://creativecommons.org/licenses/by-sa/4.0/) #### ]] ]]