Top Banner

Click here to load reader

Google app engine python

Apr 15, 2017

ReportDownload

Internet

  • GAE - PythonEueung Mulyana

    http://eueung.github.io/EL6240/gaePython CodeLabs | Attribution-ShareAlike CC BY-SA

    1 / 22

    https://github.com/eueunghttp://eueung.github.io/EL6240/gaehttps://creativecommons.org/licenses/by-sa/4.0/

  • Agenda

    GAE Basics

    Example - Guestbook

    2 / 22

  • GAE Python Basics

    3 / 22

  • Getting Started

    GAE Launcher : Add New Application

    GAE Launcher - Idle vs. Running App

    4 / 22

  • GAE Launcher -> Browse GAE Launcher -> SDK Console

    5 / 22

  • import webapp2#----------------------------------------class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello world!')#----------------------------------------app = webapp2.WSGIApplication([ ('/', MainHandler)], debug=True)

    Generated Structure/Codes

    application: helloversion: 1runtime: python27api_version: 1threadsafe: yes

    handlers:- url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico

    - url: .* script: main.app

    libraries:- name: webapp2 version: "2.5.2"

    app.yaml

    6 / 22

  • https://console.cloud.google.com -> Create Project7 / 22

    https://console.cloud.google.com/

  • https://console.cloud.google.com/home/dashboard8 / 22

    https://console.cloud.google.com/home/dashboard

  • GAE Launcher -> Dashboard9 / 22

  • Uploading

    GAE Launcher -> Deploy

    application: hello-gae-1156version: 1runtime: python27api_version: 1threadsafe: yes

    handlers:- url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico

    - url: .* script: main.app

    libraries:- name: webapp2 version: "2.5.2"

    app.yaml

    10 / 22

  • Deployed | GAE Launcher -> Dashboard11 / 22

  • Live - http://hello-gae-1156.appspot.com12 / 22

    http://hello-gae-1156.appspot.com/

  • Example - Guestbook

    13 / 22

  • A (Minimal) Guestbook

    source

    An anonymous person wrote:test dua dua dua dua dua

  • Admin | GAE Launcher -> SDK Console

    15 / 22

  • Admin | GAE Launcher -> SDK Console

    16 / 22

  • guestbook.py

    import cgiimport datetimeimport webapp2#---------------------------------------from google.appengine.ext import ndbfrom 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('/')

    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' #--------------------------------------- self.response.out.write(""" """)#---------------------------------------app = webapp2.WSGIApplication([ ('/', MainPage), ('/sign', Guestbook)], debug=True)

    17 / 22

  • application: guestbook-test-1156version: 1runtime: python27api_version: 1threadsafe: yes

    handlers:- url: .* script: guestbook.app

    libraries:- name: webapp2 version: "2.5.2"

    app.yaml

    18 / 22

  • Live19 / 22

  • Dashboard20 / 22

  • References1. Hello, World! in 5 minutes - Python Google Cloud Platform2. Introduction - Python Google Cloud Platform

    21 / 22

    https://cloud.google.com/appengine/docs/python/https://cloud.google.com/appengine/docs/python/gettingstartedpython27/introduction

  • ENDEueung Mulyana

    http://eueung.github.io/EL6240/gaePython CodeLabs | Attribution-ShareAlike CC BY-SA

    22 / 22

    https://github.com/eueunghttp://eueung.github.io/EL6240/gaehttps://creativecommons.org/licenses/by-sa/4.0/

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.