google (2) python to use and publish to google

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.

分类:Python 时间:2010-02-03 人气:215
分享到:
blog comments powered by Disqus

相关文章

  • AJAX implementation with a simple google analog input automatically 2010-12-30

    Relatively simple simulation, the text box to enter the CompanyName, and then search SqlServer2000 Suppliers table in the NorthWind database CompanyName field And then automatically complete the Four documents <!DOCTYPE html PUBLIC "-//W3C//DTD XH

  • input type = submit or button type = submit 2008-05-16

    http://www.sitepoint.com/forums/showthread.php?t=598656 AutisticCuckoo wrote An <input> button's text is specified in its value attribute, which means it can only be a simple text string. If that's all you need, using an <input> is the way to

  • 自定义input type=file 样式的方法 2014-03-27

    为什么要美化file控件?试想一下,别的孩子都穿戴整齐漂亮,其中两个孩子怎么都不鸟你,太不和谐了. 原始的file控件是这样的: <input type='file'/> 别以为这个是由一个text和一个button组合成的,它是一个控件,html代码为: <input type="file" name="file" /> 既然这样我们就用一个text和一个button来显示这个file的样式,html代码是这样: <div class

  • [Change] Ubuntu 10.04 to install Google Pinyin input method 2010-06-02

    In Ubuntu 10.04 install Google Pinyin input method, as follows: A. Get the code: (do not git to install git: sudo apt-get install git-core) $ Git clone git: / / github.com / tchaikov / scim-googlepinyin.git $ Cd scim-googlepinyin B. Compile the premi

  • Ubuntu 10.04 to install Google Pinyin input method 2010-09-13

    In Ubuntu 10.04 install Google Pinyin input method, as follows: A. Get the code: (do not git to install git: sudo apt-get install git-core) $ Git clone git: / / github.com / tchaikov / scim-googlepinyin.git $ Cd scim-googlepinyin B. Compile the premi

  • Installing Ubuntu 10.04 in Google Pinyin input method 2010-10-14

    Installing Ubuntu 10.04 in Google Pinyin input method, as follows: A. Get the code: (do not git to install git: sudo apt-get install git-core) $ Git clone git: / / github.com / tchaikov / scim-googlepinyin.git $ Cd scim-googlepinyin B. Compile the pr

  • Install in Ubuntu 10.04 Google Pinyin Input Method 2010-10-14

    Install in Ubuntu 10.04 Google Pinyin input method, as follows: A. Access Code: (not the git install git: sudo apt-get install git-core) $ Git clone git: / / github.com / tchaikov / scim-googlepinyin.git $ Cd scim-googlepinyin B. Compile the premise:

  • [Transfer] Ubuntu 10.04 to install Google Pinyin Input Method 2011-02-14

    Install in Ubuntu 10.04 Google Pinyin input method, as follows: A. Access Code: (not the git install git: sudo apt-get install git-core) $ Git clone git: / / github.com / tchaikov / scim-googlepinyin.git (Http://github.com/tchaikov/scim-googlepinyin.

  • Ubuntu10.10 install google pinyin input method 2011-03-07

    Recently installed Ubuntu 10.10, experience cool, but is the default input method does not help, feel more than 9.10 is a setback, fcitx not google or Sogou Pinyin so cool, fortunately, the project attempts to SCIM-GooglePinyin on Android Google Piny

  • Ubuntu install Google Pinyin input method (transfer) 2011-03-27

    Install in Ubuntu 10.04 Google Pinyin input method, as follows: A. Access Code: (Not the git install git: sudo apt-get install git-core) git clone git: / / github.com / tchaikov / scim-googlepinyin.git cd scim-googlepinyin B. Compile the premise: Bui

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.537 (s). 12 q(s)