Introduction
Template makes your life easier. it separating between code logic of your program to what should display on the browser. Here's I just show up what the crucial template case that not handled by Django documentation.
Displaying List of Articles
It's really some often occurance for us to display item list. It's like blog post that consits of title, date, and content. Or it like personal data that consists of name, email, address and more. Here's for example we has some blog post:
Data Content
Title | Content |
---|---|
GAE Template | GAE Template is use Django template system. So when you are accustomed for using Django, it's good for you. |
GAE Runtime | There are two available runtime for you. The first is Java and the second is Python. Whatever you choose, it should based on your preference for the language and your current skills. |
GAE Datastore | In GAE, your data is saved in database, but you never handle it directly, because Google Datastore that handles it, and in all your time, you handle the datastore. The operation for data in datastore is like in native sql, but it's more abstract than it that is called GQL - Google Query Language. |
Program code: main.py
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext.webapp import template
class Blog(db.Model): title = db.StringProperty()
content = db.TextProperty()
class MainPage(webapp.RequestHandler):
blog = Blog()
query = db.GqlQuery("SELECT * FROM Blog")
data = []
for row in query:
mapp = {}
mapp['title'] = row.title
mapp['content'] = row.content
data.append(mapp)
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext.webapp import template
class Blog(db.Model): title = db.StringProperty()
content = db.TextProperty()
class MainPage(webapp.RequestHandler):
blog = Blog()
query = db.GqlQuery("SELECT * FROM Blog")
data = []
for row in query:
mapp = {}
mapp['title'] = row.title
mapp['content'] = row.content
data.append(mapp)
No comments:
Post a Comment