google (2) python to use and publish to google

sponsored links
google (2) python to use and publish to google

I applied for a google account, huh, huh, want to try out my new release simple python application.
First of all, the python learning google entry document:
http://code.google.com/intl/zh-CN/appengine/docs/python/gettingstarted/

5 using the data store in accordance with the document, the revised helloworld.py, save the greeting message and user information to the data storage area:
import cgi
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class Greeting (db.Model):
author = db.UserProperty ()
content = db.StringProperty (multiline = True)
date = db.DateTimeProperty (auto_now_add = True)

class MainPage (webapp.RequestHandler):
def get (self):
self.response.out.write ('<html> <body>')

# Greetings = db.GqlQuery ("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")
# Two ways for writing can be, here is a kind of shorthand
greetings = Greeting.gql ("ORDER BY date DESC LIMIT 10")
for greeting in greetings:
if greeting.author:
self.response.out.write ('<b>% s </ b> wrote:'% greeting.author.nickname ())
else:
self.response.out.write ('An anonymous person wrote:')
self.response.out.write ('<blockquote>% s </ blockquote>'%
cgi.escape (greeting.content))
# Write the submission form and the footer of the page
self.response.out.write ("" "
<form action="/sign" method="post">
<div> <textarea name="content" rows="3" cols="60"> </ textarea> </ div>
<div> <input type="submit" value="Sign Guestbook"> </ div>
</ Form>
</ Body>
</ Html >""")

class Guestbook (webapp.RequestHandler):
def post (self):
greeting = Greeting ()
if users.get_current_user ():
greeting.author = users.get_current_user ()
greeting.content = self.request.get ('content')
greeting.put ()
self.redirect ('/')

application = webapp.WSGIApplication (
[('/', MainPage),
('/ Sign', Guestbook)],
debug = True)

def main ():
run_wsgi_app (application)

if __name__ == "__main__":
main ()

Start Service google_appengine / dev_appserver.py / home / sillycat / work / easyappenginepython /
Visit http://localhost:8080 to see effects. Input a few information, after being recorded and the list came out.

Clear data and start the service:
google_appengine / dev_appserver.py - clear_datastore / home / sillycat / work / easyappenginepython /

Details of the document data store:
http://code.google.com/intl/zh-CN/appengine/docs/python/datastore/

Another document presented several written GQL filtering methods:
Use positional parameters:
if users.get_current_user ():
greetings = Greeting.gql ("WHERE author =: 1 ORDER BY date DESC",
users.get_current_user ())
Use named parameters:
greetings = Greeting.gql ("WHERE author =: author ORDER BY date DESC",
author = users.get_current_user ())
API filter used to query:
greetings = Greeting.all ()
greetings.filter ("author =", users.get_current_user ())
greetings.order ("-date")

6. Use template Hey, google uses a template similar to django, modify helloworld.py file as follows:
import cgi
import os
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db

class Greeting (db.Model):
author = db.UserProperty ()
content = db.StringProperty (multiline = True)
date = db.DateTimeProperty (auto_now_add = True)

class MainPage (webapp.RequestHandler):
def get (self):
greetings_query = Greeting.all (). order ('-date')
greetings = greetings_query.fetch (10)
if users.get_current_user ():
url = users.create_logout_url (self.request.uri)
url_linktext = 'Logout'
else:
url = users.create_login_url (self.request.uri)
url_linktext = 'Login'

template_values = (
'Greetings': greetings,
'Url': url,
'Url_linktext': url_linktext,
)
path = os.path.join (os.path.dirname (__file__), 'index.html')
self.response.out.write (template.render (path, template_values))

class Guestbook (webapp.RequestHandler):
def post (self):
greeting = Greeting ()
if users.get_current_user ():
greeting.author = users.get_current_user ()
greeting.content = self.request.get ('content')
greeting.put ()
self.redirect ('/')

application = webapp.WSGIApplication (
[('/', MainPage),
('/ Sign', Guestbook)],
debug = True)

def main ():
run_wsgi_app (application)

if __name__ == "__main__":
main ()
Increase in the helloworld directory files / helloworld / index.html as follows:
<html>
<body>
(% For greeting in greetings%)
(% If greeting.author%)
<b> ((greeting.author.nickname)) </ b> wrote:
(% Else%)
An anonymous person wrote:
(% Endif%)
<blockquote> ((greeting.content | escape)) </ blockquote>
(% Endfor%)

<form action="/sign" method="post">
<div> <textarea name="content" rows="3" cols="60"> </ textarea> </ div>
<div> <input type="submit" value="Sign Guestbook"> </ div>
</ Form>
<a href="{{ url }}"> ((url_linktext)) </ a>
</ Body>
</ Html>

django template engine detailed documentation:
http://www.djangoproject.com/documentation/0.96/templates/

7. Modify configuration files using static files app.yaml:
handlers:
- Url: / stylesheets
static_dir: stylesheets
- Url: / .*
script: helloworld / helloworld.py
New directory stylesheets in engineering
New File / stylesheets / main.css, which reads as follows:
body (
font-family: Verdana, Helvetica, sans-serif;
background-color: # DDDDDD;
)
Then in the file / helloworld / index.html with the CSS application:
<head>
<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
</ Head>
ok, access http://localhost:8080 can see the added effect of the background color.

app.yaml file configuration information:
http://code.google.com/intl/zh-CN/appengine/docs/python/config/appconfig.html

8. From Application Access home page:
https: / / appengine.google.com /
I registered in the above account, a new app
sillycatkiko
My sillycat, luohuazju seemingly have it all, so I can only use the the.

Modify the project app.yaml the following documents:
application: sillycatkiko
version: 1
runtime: python
api_version: 1

handlers:
- Url: / stylesheets
static_dir: stylesheets
- Url: / .*
script: helloworld / helloworld.py

Use the command line Posted:
sillycat @ sillycat-desktop: ~ / tools $ google_appengine / appcfg.py update / home / sillycat / work / easyappenginepython /

Way I enter a user name and password.
Access address:
http://sillycatkiko.appspot.com/
You can see I have just uploaded applied. Simple experiment is completed the document. GOOGLE can see to the other documents and other applications.
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of google (2) python to use and publish to google

  • JS menu

    JS menu

  • Detailed JS regular expressions

    Opening, or have to talk about ^ and $ that they are separately used to match the beginning and end of the string, the following examples to illustrate separately "^ The": there must be at the beginning of "The" string; "of despai

  • Use Ext JS to read the JsonReader complex object json

    Today was how to resolve the following complex json object to the difficult living over a long time .. did not find documentation how to read JsonReader Ways json object (possibly also because of their limited level of E the text did not correctly underst

  • JavaScript inheritance

    About JavaScript inherited a small example ... <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 / / EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" conte ...

  • JavaScript String Functions Guinness

    Own JS function 1.Asc (x), Chr (x): convert characters, character code 2. Filter: Search string array of a specific string Format: v = filter (x, s [, include [, compare]]) Examples: Dim x ()={" kjwang "," wangkj "," peter ")

  • EJB ant script to deploy template works

    <? xml version = "1.0" encoding = "UTF-8"?> <! - Name Project name basedir build.xml file directory -> <project name="HelloWorld" basedir="."> <! - Property variables -> <! - The sour ...

  • NoClassDefFoundError: javax / servlet / Servlet

    In the project in order to achieve a listener in web.xml set up a listener, did start in Tomcat actually occurred after java.lang.NoClassDefFoundError: javax / servlet / ServletContextListener this anomaly google and found the reasons for the lack of serv

  • java read file

    java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to understa

  • spring myfaces hibernate richfaces

    1.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j

  • The level Hibernate cache

    Hibernate cache level: (1) a cache is very short and the session life cycle consistent, also known as session-level cache-level cache or transaction-level cache (2) Ways of Supporting level cache: get (); load (); iterator (); only entity object cach ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries