打印
[嵌入式linux]

用google app engine和django做网站的一些知识记录

[复制链接]
7104|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
sinanjj|  楼主 | 2010-8-25 20:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sinanjj 于 2010-8-27 18:58 编辑

http://code.google.com/appengine/docs/

gae可以用两种语言开发, java和python.
我选python, 看python的.:
  • a fast Python 2.5 interpreter in a secure sandbox environment
  • python2.5版本
  • includes the complete Python standard library
  • 包含标准库.
  • supports popular web application frameworks, including Django
  • 支持主流web开发框架, 包括django
  • works with any application that supports CGI or WSGI
  • 实际上只要支持cgi或者wsgi就行.




http://code.google.com/appengine ... devenvironment.html

The Development Environment
the开发环境.
You develop and upload Python applications for Google App Engine using the App Engine Python software development kit (SDK).
The Python SDK includes a web server application that simulates the App Engine environment, including a local version of the datastore, Google Accounts, and the ability to fetch URLs and send email directly from your computer using the App Engine APIs. The Python SDK runs on any computer with Python 2.5, and versions are available for Windows, Mac OS X and Linux. (The Python SDK is not compatible with Python 3.)
python的googleapp开发环境包含了一个web服务器程序, 这个web服务器程序仿真了googleapp的环境. 这个SDK可运行与任何装了python2.5的环境中, 包含linux, windows mac (这个sdk与python3不兼容) (意思就是sdk本身就是python2.5写的)

Download the App Engine SDK. Follow the instructions on the download page to install the SDK on your computer.
下载appengine sdk, 安装.
(插入安装过程
http://code.google.com/appengine/downloads.html
linux版本下载地址:
http://googleappengine.googlecode.com/files/google_appengine_1.3.6.zip
解压就能用
)

相关帖子

沙发
sinanjj|  楼主 | 2010-8-25 22:14 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 19:01 编辑

http://code.google.com/appengine ... ted/helloworld.html


Hello, World! 例子

Creating a Simple Request Handler
建立一个简单的请求处理程序
Create a directory named helloworld. All files for this application reside in this directory.
建立一个名为helloworld的目录, 这个web程序所有的相关文件都放在这个目录里.
Inside the helloworld directory, create a file named helloworld.py, and give it the following contents:
在这个helloworld目录里, 创建一个名为helloworld.py的文件, 填入以下内容(直接copy进去)

print 'Content-Type: text/plain'
print ''
print 'Hello, world!'

This Python script responds to a request with an HTTP header that describes the content, a blank line, and the message Hello, world!.
这个python脚本回复了一个http请求, 返回一个http头描述, 一个空行分栏, 和文本信息: hello world.

Creating the Configuration File

An App Engine application has a configuration file called app.yaml. Among other things, this file describes which handler scripts should be used for which URLs.
每个gap的应用程序都得有一个叫app.yaml的设置文件. 这个文件实际就是url和应用程序的对应(一般的web框架干这事)


Inside the helloworld directory, create a file named app.yaml with the following contents:
在helloworld目录里, 创建app.yaml文件, 里边填充下列内容(直接copy过去)

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: helloworld.py

From top to bottom, this configuration file says the following about this application:
这个设置文件说了一下信息:
    * The application identifier is helloworld. When you register your application with App Engine in the final step, you will select a unique identifier, and update this value. This value can be anything during development. For now, leave it set to helloworld.
程序的唯一标识符是helloworld. 当你在gap服务器注册这个程序的时候, 得选个唯一标识符来标明这个程序. 开发过程中这个值意义不大(可以是anything). (就是程序名, 虽然你可以起任何的名字, 但最好还是开始想好自己要干什么)

    * This is version number 1 of this application's code. If you adjust this before uploading new versions of your application software, App Engine will retain previous versions, and let you roll back to a previous version using the administrative console.
这个程序的版本是1. gap自动更新并保留旧的版本. 你可以用管理终端来切换版本.

    * This code runs in the python runtime environment, version "1". Additional runtime environments and languages may be supported in the future.
代码是python代码, 用的是版本1的gap环境.

    * Every request to a URL whose path matches the regular expression /.* (all URLs) should be handled by the helloworld.py script.
任何请求的url符合/.*这个正则表达式的, 都应该由helloworld脚本处理(就是一切请求都回个helloworld-----这程序绝对没漏洞....)

The syntax of this file is YAML. For a complete list of configuration options, see the app.yaml reference.
yaml就是这个格式. 看所有设置关键字看app.yaml参考

Testing the Application
测试这个程序
With a handler script and configuration file mapping every URL to the handler, the application is complete. You can now test it with the web server included with the App Engine SDK.
有了url处理脚本和url映射文件, 这个web应用程序基本算全了(真简洁啊....). 我们先用sdk内置的webserver来测试他.

$ ./dev_appserver.py helloworld/
用这个命令来测试helloworld应用. 命令的参数是helloworld文件夹的地址(绝对的或相对的)

The web server is now running, listening for requests on port 8080. You can test the application by visiting the following URL in your web browser:
现在webserver就运行了, 监听8080端口着呢. 直接用浏览器看看把. 用一下地址.
http://localhost:8080/

You can leave the web server running while you develop your application. The web server knows to watch for changes in your source files and reload them if necessary.
你每改动一次代码, 这个webserver就自动从载一次(所谓交互式开发么).

使用特权

评论回复
板凳
sinanjj|  楼主 | 2010-8-25 22:39 | 只看该作者
本帖最后由 sinanjj 于 2010-8-28 14:15 编辑

http://code.google.com/appengine ... ed/usingwebapp.html

Using the webapp Framework
使用webapp开发框架

The CGI standard is simple, but it would be cumbersome to write all of the code that uses it by hand. Web application frameworks handle these details for you, so you can focus y**elopment efforts on your application's features. Google App Engine supports any framework written in pure Python that speaks CGI (and any WSGI-compliant framework using a CGI adaptor), including Django, CherryPy, Pylons, and web.py. You can bundle a framework of your choosing with your application code by copying its code into your application directory.
cgi标准比较简单比较笨重, 所以我们有必要使用写web开发框架来简化些. gap支持绝大部分python的开发框架(WSGI标准的),包括但不限于: django, cheerypy pylons, web.py. 你可以将开发框架和代码放在一个目录里作为一个应用程序.

App Engine includes a simple web application framework of its own, called webapp. The webapp framework is already installed in the App Engine environment and in the SDK, so you do not need to bundle it with your application code to use it. We will use webapp for the rest of this tutorial.
gap已经自带了一个简单的web开发框架啦, 叫webapp(牛啊, 记得不久前还是django的...). 我们下边的教程就已webapp为例(想用gap而且不折腾就老老实实的用webapp吧..实际上所有的开发框架都大同小异啊)


Hello, webapp!
用webapp做的helloworld程序
A webapp application has three parts:
一个webapp程序有3个部分:
    * one or more RequestHandler classes that process requests and build responses
多个请求处理类. 返回回复内容.
    * a WSGIApplication instance that routes incoming requests to handlers based on the URL
一个url和handler的映射表.
    * a main routine that runs the WSGIApplication using a CGI adaptor
将cgi调用变成wsgi调用的东西???(存在疑问)

Let's rewrite our friendly greeting as a webapp application. Edit helloworld/helloworld.py and replace its contents with the following:
编辑helloworld/helloworld.py, 填充以下内容(直接copy就行啦)

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['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

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

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()

(WSGI标准就是j8诡异啊)
Reload http://localhost:8080/ in your browser to see the new version in action. (If you stopped your web server, restart it by running the command described in "Hello, World!".)
刷新下 http://localhost:8080/ , 如果关了测试服务器, 从开下


What webapp Does
webapp干了什么

The webapp module is in the google.appengine.ext package. This module is provided in the SDK, as well as in the production runtime environment.
webapp模块在google.appengine.ext包中.  SDK自带的.

This code defines one request handler, MainPage, mapped to the root URL (/). When webapp receives an HTTP GET request to the URL /, it instantiates the MainPage class and calls the instance's get method. Inside the method, information about the request is available using self.request. Typically, the method sets properties on self.response to prepare the response, then exits. webapp sends a response based on the final state of the MainPage instance.
代码定义了一个url请求处理类. MainPage, 映射对url / , 当一个对url /的请求被webapp收到时, 他立即调用MainPage类, 并调用这个实例的get方法. 在这个方法中, 请求的信息都放在self.request变量中, 一般的, 这个方法将要回复的信息放入self.response, 当退出的时候, webapp根据self.response来产生回复信息.

The application itself is represented by a webapp.WSGIApplication instance. The parameter debug=true passed to its constructor tells webapp to print stack traces to the browser output if a handler encounters an error or raises an uncaught exception. You may wish to remove this option from the final version of your application.

The function run_wsgi_app() takes a WSGIApplication instance (or another WSGI-compatible application object) and runs it in App Engine's CGI environment. run_wsgi_app() is similar to the WSGI-to-CGI adaptor provided by the wsgiref module in the Python standard library, but includes a few additional features. For example, it can automatically detect whether the application is running in the development server or on App Engine, and display errors in the browser if it is running on the development server.

We'll use a few more features of webapp later in this tutorial. For more information about webapp, see the webapp reference.
Next...

Frameworks make web application development easier, faster and less error prone. webapp is just one of many such frameworks available for Python. Now that we're using a framework, let's add some features.

Continue to Using the Users Service.



(比django差了不是一点半点, 还是用django吧...)

使用特权

评论回复
地板
sinanjj|  楼主 | 2010-8-25 23:38 | 只看该作者
本帖最后由 sinanjj 于 2010-8-28 14:53 编辑

http://code.google.com/appengine ... ted/usingusers.html

Using the Users Service
使用用户服务

Google App Engine provides several useful services based on Google infrastructure, accessible by applications using libraries included with the SDK. One such service is the Users service, which lets your application integrate with Google user accounts. With the Users service, your users can use the Google accounts they already have to sign in to your application.
这一段说明了users service 是什么玩意, 就是google的整体构架是集成的, 用gap创建的程序可以调用google的账户, 就是你创建个需要用户名/密码管理的网站, 用户名用google账户的就是了.(省去了用户名/密码数据库.)



Using Users
from google.appengine.api import users
        user = users.get_current_user()
        if user:
            self.response.out.write('Hello, ' + user.nickname())
        else:
            self.redirect(users.create_login_url(self.request.uri))

使用特权

评论回复
5
sinanjj|  楼主 | 2010-8-26 12:25 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 21:05 编辑

http://code.google.com/appengine ... /handlingforms.html

Handling Forms with webapp
表单的处理.
假定以下表单:
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="SignGuestbook"></div>
</form>
表单处理类:
class Guestbook(webapp.RequestHandler):
def post(self):
self.response.out.write('<html><body>You wrote:<pre>')
self.response.out.write(cgi.escape(self.request.get('content')))
self.response.out.write('</pre></body></html>')

application = webapp.WSGIApplication(
[('/',
MainPage),
('/sign',
Guestbook)])  url对应

Reload the page to see the form, then try submitting a message.
查看测试程序的结果, 试着在看到的表单里提交点内容.

The Guestbook handler has a post() method instead of a get() method.  This is because the form displayed by MainPage uses the HTTP POST method (method="post") to submit the form data.  If for some reason you need a single handler to handle both GET and POST actions to the same URL, you can define a method for each action in the same class.
这回自动调用的是post方法, 如果是get的时候就自动调用get方法啦.

The code for the post() method gets the form data from self.request.  Before displaying it back to the user, it uses cgi.escape() to escape HTML special characters to their character entity equivalents.  cgi is a module in the standard Python library; see the documentation for cgi for more information.
cgi.escape()函数用来去除html内容(防止某些别有用心的人搞破坏.)
Note: The App Engine environment includes the entire Python 2.5 standard library.  However, not all actions are allowed.  App Engine applications run in a restricted environment that allows App Engine to scale them safely.  For example, low-level calls to the operating system, networking operations, and some filesystem operations are not allowed, and will raise an error when attempted.  For more information, see The Python Runtime Environment.
注意: 一些底层的调用是不允许的, 包括网络操作, 文件系统操作.

Next...Now that we can collect information from the user, we need a place to put it and a way to get it back.
Continue to Using the Datastore.

使用特权

评论回复
6
sinanjj|  楼主 | 2010-8-26 16:42 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 22:36 编辑

http://code.google.com/appengine ... usingdatastore.html

Using the Datastore
使用datastore

A Complete Example Using the Datastore
使用datastore的例子

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")

        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()

Storing the Submitted Greetings
保存提交的greetings
App Engine includes a data modeling API for Python. It's similar to Django's data modeling API, but uses App Engine's scalable datastore behind the scenes.
gap包含一个操作数据模型的api, 类似django的数据模型api.

For the guestbook application, we want to store greetings posted by users. Each greeting includes the author's name, the message content, and the date and time the message was posted so we can display messages in chronological order.
在这个例子中, 我们意图保存每一条问候语句, 包含问候着名字, 信息内容, 数据, 时间.

To use the data modeling API, import the google.appengine.ext.db module:
第一步先引入google model api:
from google.appengine.ext import db
The following defines a data model for a greeting:
针对问候定义一个数据模型:
class Greeting(db.Model):
    author = db.UserProperty()
    content = db.StringProperty(multiline=True)
    date = db.DateTimeProperty(auto_now_add=True)

This defines a Greeting model with three properties: author whose value is a User object, content whose value is a string, and date whose value is a datetime.datetime.
这个定义的模型包含了3个数据条目: author, 属性是用户类, content, 是个字符串, data是个时间类

Some property constructors take parameters to further configure their behavior. Giving the db.StringProperty constructor the multiline=True parameter says that values for this property can contain newline characters. Giving the db.DateTimeProperty constructor a auto_now_add=True parameter configures the model to automatically give new objects a date of the time the object is created, if the application doesn't otherwise provide a value. For a complete list of property types and their options, see the Datastore reference.

Now that we have a data model for greetings, the application can use the model to create new Greeting objects and put them into the datastore. The following new version of the Guestbook handler creates new greetings and saves them to the datastore:
下面当然是使用这个新定义的模型来放入
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('/')

This new Guestbook handler creates a new Greeting object, then sets its author and content properties with the data posted by the user. It does not set the date property, so date is automatically set to "now," as we configured the model to do.
在guestbook处理函数中, 创建了一个新的greeting对象, 然后设置它的anthor和content属性. 时间属性会自动设置为当前时间.

Finally, greeting.put() saves our new object to the datastore. If we acquired this object from a query, put() would update the existing object. Since we created this object with the model constructor, put() adds the new object to the datastore.
最后, greeting.put()保存这个新建立的对象到datastore. 如果我们从一次查询中得到的这个对象, pur()方法将更新现存的对象.

Retrieving the Stored Greetings With GQL
使用gql将存放的greeting对象取出来

The App Engine datastore has a sophisticated query engine for data models. Because the App Engine datastore is not a traditional relational database, queries are not specified using SQL. Instead, you can prepare queries using a SQL-like query language we call GQL. GQL provides access to the App Engine datastore query engine's features using a familiar syntax.
gae使用的datastore是google自己开发的, 非常规关系数据库(传说是no-sql类hash表云存储), 所以你也别指望用sql啦. 这里有个类似的, gql.

The query happens on this line:
查询发生在这一行:
    greetings = db.GqlQuery("SELECT * FROM Greeting ORDER BY date DESC LIMIT 10")

Alternatively, you can call the gql(...) method on the Greeting class, and omit the SELECT * FROM Greeting from the query:
达到同样的目的你可以使用如下语句
    greetings = Greeting.gql("ORDER BY date DESC LIMIT 10")

A GQL query can have a WHERE clause that filters the result set by one or more conditions based on property values. Unlike SQL, GQL queries may not contain value constants: Instead, GQL uses parameter binding for all values in queries. For example, to get only the greetings posted by the current user:
过滤: 下边是一个过滤出当年用户的例子

    if users.get_current_user():
        greetings = Greeting.gql("WHERE author = :1 ORDER BY date DESC",
                                 users.get_current_user())
You can also use named parameters instead of positional parameters:
        greetings = Greeting.gql("WHERE author = :author ORDER BY date DESC",
                                 author=users.get_current_user())
For a complete description of GQL and the query APIs, see the Datastore reference.
Clearing the Development Server Datastore

The development web server uses a local version of the datastore for testing your application, using temporary files. The data persists as long as the temporary files exist, and the web server does not reset these files unless you ask it to do so.

If you want the development server to erase its datastore prior to starting up, use the --clear_datastore option when starting the server:
用如下命令清空本地的测试datastore:
dev_appserver.py --clear_datastore helloworld/

使用特权

评论回复
7
sinanjj|  楼主 | 2010-8-26 18:24 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 11:37 编辑

http://code.google.com/appengine ... rted/templates.html


Using Templates
使用模板

helloworld/helloworld.py:
import os
from google.appengine.ext.webapp import template  # 导入模板包
class MainPage(webapp.RequestHandler):
    def get(self):
        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))

Finally, create a new file in the helloworld directory named index.html, with the following contents:
最后, 创建一个新的文件, 命名为index.html, 填充以下内容(就是模板文件啦)

<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>

Reload the page, and try it out.
测试下.

template.render(path, template_values) takes a file path to the template file and a dictionary of values, and returns the rendered text. The template uses Django templating syntax to access and iterate over the values, and can refer to properties of those values. In many cases, you can pass datastore model objects directly as values, and access their properties from templates.
template.render(path, template_values) 就这个函数啦. 使用了django的模板语法.(估计就是用的django的解析器)

Tip: An App Engine application has read-only access to all of the files uploaded with the project, the library modules, and no other files. The current working directory is the application root directory, so the path to index.html is simply "index.html".
注意: 项目的目录就是当前根目录. 所以放在helloworld目录的index直接就是indexpath啦

For more information about the Django templating engine, see the Django 0.96 template documentation.
Next...

Every web application returns dynamically generated HTML from the application code, via templates or some other mechanism. Most web applications also need to serve static content, such as images, CSS stylesheets, or JavaScript files. For efficiency, App Engine treats static files differently from application source and data files. You can use App Engine's static files feature to serve a CSS stylesheet for this application.

Continue to Using Static Files.

下一步讲如何将静态文件(图片啊, js文件啊. css文件啊, 等)分离

使用特权

评论回复
8
sinanjj|  楼主 | 2010-8-26 18:51 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 15:33 编辑

http://code.google.com/appengine ... ed/staticfiles.html

Using Static Files
使用静态文件
Edit helloworld/app.yaml and replace its contents with the following:
编辑, hellpworld/app.yaml. (注意啦, 这回是app.yaml啦), 填充内容如下:

application: helloworld
version: 1
runtime: python
api_version: 1

handlers:
- url: /stylesheets
  static_dir: stylesheets

- url: /.*
  script: helloworld.py

The new handlers section defines two handlers for URLs. When App Engine receives a request with a URL beginning with /stylesheets, it maps the remainder of the path to files in the stylesheets directory and, if an appropriate file is found, the contents of the file are returned to the client. All other URLs match the / path, and are handled by the helloworld.py script.
这个设置定义了, 当url请求是/stylesheets时, 就回到stylesheets文件夹查找对应文件. 如果找到文件就返回文件内容.其他的请求都会被helloworld.py处理.

Create the directory helloworld/stylesheets. In this new directory, create a new file named main.css with the following contents:
创造文件夹helloworld/stylesheets, 在这个文件夹里创造一个名为main.css的新文件.
填充一下内容:

body {
  font-family: Verdana, Helvetica, sans-serif;
  background-color: #DDDDDD;
}

Finally, edit helloworld/index.html and insert the following lines just after the <html> line at the top:
然后编辑index.html来访问这个静态文件.

  <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
  </head>

Reload the page in your browser. The new version uses the stylesheet.
当然啦, 最后测试下结果看看.
Next...

The time has come to reveal your finished application to the world.

Continue to Uploading Your Application.
下一步, 展示如何上传你最终的设计到gae

使用特权

评论回复
9
sinanjj|  楼主 | 2010-8-26 20:50 | 只看该作者
本帖最后由 sinanjj 于 2010-8-27 11:09 编辑

Uploading Your Application
上传些好的应用程序
首先开通一个googleappenergy, 现注册个gmail, 然后在首页点击signup开通.
需要一个手机号

创建url为http://*****.appspot.com/的应用.

直接以下命令上传:
$./appcfg.py update helloworld/

查看结果:
http://application-id.appspot.com

使用特权

评论回复
10
sinanjj|  楼主 | 2010-8-26 21:05 | 只看该作者
本帖最后由 sinanjj 于 2010-8-26 21:16 编辑

gae不能改动静态文件, 也就是动态内容/增加内容只能放在datastore, 我们回来看看datastore的所有项


http://code.google.com/appengine/docs/python/datastore/

http://code.google.com/appengine ... store/overview.html

Datastore Python API Overview
(卧槽, 这么长..)

The Google App Engine datastore provides robust scalable data storage for your web application. The datastore is designed with web applications in mind, with an emphasis on read and query performance. It stores data entities with properties, organized by application-defined kinds. It can perform queries over entities of the same kind, with filters and sort orders on property values and keys. All queries are pre-indexed for fast results over very large data sets. The datastore supports transactional updates, using entity groupings defined by the application as the unit of transactionality in the distributed data network.

Introducing the Datastore
The App Engine datastore stores and performs queries over data objects, known as entities. An entity has one or more properties, named values of one of several supported data types. A property can be a reference to another entity.


....

这个文件跳过.


直接到这里看datatype:

http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html


Types and Property ClassesThe App Engine datastore supports a fixed set of value types for properties on data entities.  Property classes can define new types that are converted to and from the underlying value types, and the value types can be used directly with Expando dynamic properties and ListProperty aggregate property models.

The following table describes the Property classes whose values correspond directly with the underlying data types.  Any of these value types can be used in an Expando dynamic property or ListProperty aggregate type.
                                          
Property classValue typeSort order
StringProperty      str
      unicode   
Unicode (str is treated as ASCII)
ByteStringProperty      ByteString
   
byte order
BooleanPropertyboolFalse < True
IntegerProperty      int
      long (64 bits)
   
Numeric
FloatPropertyfloatNumeric
      DateTimeProperty
      DateProperty
      TimeProperty
   
datetime.datetimeChronological
      ListProperty
      StringListProperty   
list of a supported typeIf ascending, by least element; if descending, by greatest element
      ReferenceProperty
      SelfReferenceProperty   
db.KeyBy path elements (kind, ID or name, kind, ID or name...)
blobstore.BlobReferencePropertyblobstore.BlobKeybyte order
UserPropertyusers.UserBy email address (Unicode)
BlobPropertydb.Blob(not orderable)
TextPropertydb.Text(not orderable)
CategoryPropertydb.CategoryUnicode
LinkPropertydb.LinkUnicode
EmailPropertydb.EmailUnicode
GeoPtPropertydb.GeoPtBy latitude, then longitude
IMPropertydb.IMUnicode
PhoneNumberPropertydb.PhoneNumberUnicode
PostalAddressPropertydb.PostalAddressUnicode
RatingPropertydb.RatingNumeric




使用特权

评论回复
11
sinanjj|  楼主 | 2010-8-26 21:18 | 只看该作者
本帖最后由 sinanjj 于 2010-8-26 21:25 编辑

class StringProperty(verbose_name=None, multiline=False, ...)
    A short string property. Takes a Python str or unicode (basestring) value of 500 characters or less.
    StringProperty property values are indexed, and can be used in filters and sort orders.
    If multiline is False, then the value cannot include linefeed characters. The djangoforms library uses this to enforce a difference between text fields and textarea fields in the data model, and others can use it for a similar purpose.
    If the StringProperty is required, the value cannot be an empty string.
    Value type: str or unicode

class TextProperty()
    A long string.
    Unlike StringPropety, a TextProperty value can be more than 500 characters long. However, TextProperty values are not indexed, and cannot be used in filters or sort orders.
    TextProperty values store text with a text encoding. For binary data, use BlobProperty.
    If the TextProperty is required, the value cannot be an empty string.
    Value type: Text


意思就是500个字节内的用string, 评论啥的估计就是text啦



基本的设计:

基本的元素(伪码)
负面评论:
     用户(就是谁发表了这个评论, 索引?)
    评论内容(text域, 不限长度的, 就是骂多少都行)
    证据图片. (怎么放我们还不知道, 不过证据肯定是用图片的.)

使用特权

评论回复
12
sinanjj|  楼主 | 2010-9-7 17:23 | 只看该作者
========================华丽的分隔符============================


下边看看

GAE 的 URL Fetch


用它架设代理. 目标是建立一个比较实用的代理.

使用特权

评论回复
13
sinanjj|  楼主 | 2010-9-7 17:24 | 只看该作者
本帖最后由 sinanjj 于 2010-9-7 17:27 编辑

http://code.google.com/appengine/docs/python/urlfetch/


The URL Fetch Python API

App Engine applications can fetch resources and communicate with other hosts over the Internet using HTTP and HTTPS requests. Apps use the URL fetch service to make requests.
GAE能利用URL fetch服务, 来向别的服务器发起请求. (就是代理)
This reference describes the Python API for the URL fetch service. It has the following sections:
目录:

    * Overview 简介
    * Reference
          o The fetch Function功能
          o Asynchronous Requests 异步请求
          o Response Objects 类
          o Exceptions 出错反映

使用特权

评论回复
14
sinanjj|  楼主 | 2010-9-7 17:27 | 只看该作者
null

使用特权

评论回复
15
sinanjj|  楼主 | 2010-9-7 17:29 | 只看该作者
本帖最后由 sinanjj 于 2010-9-7 17:34 编辑

http://code.google.com/appengine ... fetch/overview.html

URL Fetch Python API Overview
用python调用任一url资源, 简介

App Engine applications can communicate with other applications or access other resources on the web by fetching URLs. An app can use the URL Fetch service to issue HTTP and HTTPS requests and receive responses. The URL Fetch service uses Google's network infrastructure for efficiency and scaling purposes.

    * Fetching URLs in Python 介绍
    * Making Requests   发起请求
    * Secure Connections and HTTPS https请求
    * Request Headers 定制请求头
    * Responses  返回
    * Contacting Hosts Behind Your Company's Firewall  穿越防火墙
    * URL Fetch and the Development Server 获取url
    * Quotas and Limits 不足






Fetching URLs in PythonYou can use the Python standard libraries urllib, urllib2 or httplib to make HTTP requests.  When running in App Engine, these libraries perform HTTP requests using App Engine's URL fetch service, which runs on Google's scalable HTTP request infrastructure.
import urllib2

url =
"http://www.google.com/"
try:
  result = urllib2.urlopen(url)
  doSomethingWithResult(result)
except urllib2.URLError, e:
  handleError(e)You can also access the URL fetch service using its Python API.  In this API, the urlfetch.fetch() function performs an HTTP request.
from google.appengine.api import urlfetch

url =
"http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code ==
200:
  doSomethingWithResult(result.content)The URL fetch service supports five HTTP methods: GET, POST, HEAD, PUT and DELETE.  The request can include HTTP headers, and body content for a POST or PUT request.  For example, to submit data to a web form handler using the POST action using the URL fetch API:
import urllib

form_fields =
{
"first_name":
"Albert",
"last_name":
"Johnson",
"email_address":
"Albert.Johnson@example.com"
}
form_data = urllib.urlencode(form_fields)
result = urlfetch.fetch(url=url,
                        payload=form_data,
                        method=urlfetch.POST,
                        headers={'Content-Type':
'application/x-www-form-urlencoded'})

使用特权

评论回复
16
sinanjj|  楼主 | 2011-10-6 16:10 | 只看该作者
本帖最后由 sinanjj 于 2011-10-6 16:28 编辑

Google_App_Engine 已经被GFW彻底被屏蔽.

http://sae.sina.com.cn/类似.

不过, 不能开udp服务器. 基本无用.

使用特权

评论回复
17
原野之狼| | 2011-10-8 17:01 | 只看该作者
app_engine  N久之前就不能用了  伤不起啊

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:In God We Trust 独立的个人,体赖科学技术工具提供针对个人的产品与服务,是通向幸福的唯一道路 工程师,设计师等可以个人创业的群体,将逐步瓦解官僚体制公司,成为中国中产。(重复劳动,工厂等,将逐步机械化) seacer.co

456

主题

6300

帖子

25

粉丝