mi primera aplicacion en google app engine
DESCRIPTION
Presentacion para el segundo Barcamp en Guatemala sobre Google App EngineTRANSCRIPT
Mi Primera Aplicacion usandoGoogle App Engine
Adrian Catalan
Y que es eso del GAE?
Google App Engine es una plataforma de desarrollo Python & Java
Cloud Computing Todo como un servicio
I have not heard two people say the same thing about it [cloud]. There are multiple definitions out there of “the cloud”
Andy Isherwood, HP’s Vice President of European Software Sales
Google App Engine
Tenemos por seguro que hace una cosa bien: correr aplicaciones web
Y ademas... Simple Escalable Seguro Balanceo de carga
Google App Engine
Datastore Big Table y GQL
Frameworks Django (hell yeah...!) CherryPy Webapp WSGI
Servicios (google accounts, mail, url fetch & mas)
App Engine Architecture
5
PythonVM
process
stdlib
app
memcachedatastore
images
urlfech
statefulAPIs
stateless APIs R/O FS
req/resp
Por que voy a dejar de usar LAMP?
Pareciera ser EL estandar ...pero
Configuracion Tuning Problemas con el Hardware Updates Y mas
Datastore
Las Entidades tienen Kind, Key, y Propiedades Entity ~~ Record ~~ Python dict ~~ Python class
instance Key ~~ structured foreign key; includes Kind Kind ~~ Table ~~ Python class Property ~~ Column or Field; has a type
Desventajas
Ambiente muy controlado Solo Python y Java por el momento
Facil de usar ...pero limitado (gratis)
Si los frameworks estan atados a bd relacionales, de que forma pasaran a ser parte de GAE?
Cuando usar GAE
Queremos tenerlo funcionando ASAP Empezando un proyecto nuevo Conocemos Python Las limitaciones no son un problema para nosotros No estamos en un proyecto muy grande con cosas
dificiles de implementar
Google App Engine
Hacia donde vamos?
Google App Engine
Y ahora...vamos al demo
Como empezamos?
Descargamos el SDK (duh!) dev_appserver.py appcfg.py
Hola, mundo...desde la nube!
print 'ContentType: text/plain'
print ' '
print 'Hello, world!'
Y la configuracion? (app.yaml)
application: helloworld
version: 1
runtime: python
api_version: 1
handlers:
url: /.*
script: helloworld.py
Empezando a usar webapp
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['ContentType'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
Empezando a usar webapp
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Usando el servicio de usuarios
users.get_current_user() create_login_url(dest_url) get_current_user()
ElModelo
class BlogEntry(db.Model):
author = db.UserProperty()
title = db.StringProperty()
content = db.StringProperty(multiline=True)
date=db.DateTimeProperty(auto_now_add=True)
El resto de ElModelo
class BlogComment (db.Model):
author = db.UserProperty()
content = db.StringProperty(multiline=True)
date=db.DateTimeProperty(auto_now_add=True)
entry = db.ReferenceProperty(BlogEntry,collection_name='cm')
Agregando al Datastore
class Entry (webapp.RequestHandler):
def post(self):
en = BlogEntry()
en.author = users.get_current_user()
en.content = self.request.get('content')
en.title = self.request.get('title')
en.put()
self.redirect('/')
Templates de Django
class MainPage(webapp.RequestHandler):
def get(self):
query = BlogEntry.all().order('date')
entries = query.fetch(3)
template_values = {
'entries': entries,
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
Templates de Django
{% for entry in entries %}
<a href="/show?key={{ entry.key }}"><b>{{ entry.title }}</b></a>
<blockquote>{{ entry.content|escape }}</blockquote>
<small>Publicado por <b>{{ entry.author.nickname }}</b></small>
<hr/>
{% endfor %}
Indicando rutas
application = webapp.WSGIApplication(
[('/', MainPage),
('/comment', Comment),
('/entry', Entry),
('/show', ShowEntry),
('/publish', PublishEntry)],
debug=True)
El codigo lo encuentran en
http://www.megaupload.com/?d=0XUF9QIG
Preguntas || kthxbye