I have been playing with the Google App Engine this weekend. I just need to write something by hand. Please correct me more.
Author: liigo, 2009/04/26, Dalian
Original: http://blog.csdn.net/liigo/archive/2009/04/26/4127055.aspx
Reprinted please indicate the source: http://blog.csdn.net/liigo
I. How do I get started with Google App Engine?
Recently I want to write a small program to share data between my company's computer and my home computer at any time. However, if there is no ready-made server or virtual host, it becomes a problem where the data exists. Isn't it worthwhile to rent a virtual host for this small item. Google App Engine (Gae) allows users to deploy Web applications on Google servers for free, which naturally meets my needs.
2. What is Google App Engine?
Strictly defined to go to the official website (http://code.google.com/intl/en/appengine/) Find it, I (liigo) popular understanding, it is similar to the virtual host thing, allows you to deploy a good web application (web site) on its server. For example, "PHP + MySQL" and "ASP + sqlserver" virtual host services are available everywhere on the network, generally, the annual fee ranges from several hundred yuan to thousands of yuan; google App Engine provides "Python + datastore" and "Java Servlet/JSP + datastore" virtual host services for free (datastore is a database provided by Google, the App Engine datastore is a schemaless object datastore, with a query engine and atomic transactions .). Our programs run on Google servers and use Google's CPU and bandwidth to enjoy the security, flexibility, scalability, and load balancing of Google's excellent network architecture. Google App Engine provides 5 million MB of storage space for each program free of charge, ample CPU (up to 46cpu-hours per day) and bandwidth (up to 10 Gb of upload/download traffic each day), and clicks per month, enough to meet the needs of most projects (pay-as-you-go extension if necessary), while common virtual hosts that provide equivalent performance are expensive. Currently, Google App Engine only supports Python and Java. Other programming languages (PHP, Ruby, Perl, ASP, esp?) will be supported in the plan ?). I personally think that the future of Google App Engine is limitless and will gradually break into the current virtual hosts market. Currently, it only supports Python and Java, which is obviously not the first choice for web development.
3. Python or Java?
Google App Engine currently only supports Python and Java, which is a two-choice problem. From the perspective of programming languages, I should select Java, but considering the fast and convenient development, I finally chose Python that I was not very familiar with (or even excluded for a while. Writing web with Java is not necessarily the best choice, just like writing a server with easy language.
4. Google App Engine tour
According to the step-by-step tutorial, the first program was successfully deployed at the beginning.
Iv. 1Files such as app. yaml *. py can be modified immediately and take effect without restarting the web server.
Iv. 2Library path, so tired. The error "importerror" was reported when the webapp (and later webob, CGI) was exposed. It seems that the corresponding Python library could not be found (haha, I thought that only the easy language would prompt "unable to load the support library"). After searching for half a day, I finally solved the problem by setting the system environment variable pythonpath. Its value is:
D:/python25/LIB; D:/program files/Google/google_appengine/lib/webob
I thought this was an oversight of the Google App Engine Python SDK installation package. I didn't correctly set the relevant library path, which caused beginners to get stuck for half a day. It is hard for beginners to Understand Java classpath. Python's pythonpath and SYS. Path are also difficult to understand. Let alone ef_lib_paths is not introduced in EF. More.
Iv. 3You cannot use a class before it is defined. The core code of webapp:
Application = webapp. wsgiapplication ([('/Index', mainpage)], DEBUG = true)
I tried it specially and moved the mainpage class definition to the bottom of this line. Oh, my God, the error of full screen gave me a try again. It can be seen that, although it is a scripting language, it cannot come along with the child. But I really want to write this line at the beginning of the source file, because the entire program structure is concentrated here.
Iv. 4The letters in the URL are case-sensitive. For example, http: // localhost: 8080/index cannot be written as.../index. This is not good and should be corrected.
Iv. 5I am stuck with the syntax for formatting text in Python for half a day. There is such a write ("% s" % A) in the routine, I want to add another "% s" and tried various syntaxes, write ("% S % s" % A % B), write ("% S % s", a, B), and so on. Google also tortured me, you are not allowed to search for the "Python % s" keyword. Later, you can search for "Python Format String" to find the correct answer: Write ("% S % s" % (A, B )). Haha, the joy of exploration.
Iv. 6Convert the text to an integer using the INT () function. Delete a post according to an ID. The first result is the text form of the ID (self. request. get ('id'), first convert to an integer and then go to the database to find the corresponding record (dB. model. get_by_id ()). Not familiar with the Python language. It takes half a day to search for the INT () function. C/C ++, I know that I use atoi (); Java, I know that I use integer. parseint (); if it is Delphi, I know to use strtoint (); if it is easy language, I know to use "to INTEGER ()"; if EF, I know to use "text class. to INTEGER () "; but in Python, I need to search for half a day to find int ().
Iv. 7Google's database datastore. It is not a traditional relational database, but an object-type database; it does not support standard SQL, but has similar gql. To use it in Python, you must first define an inherited from DB. the model class (mymodel) specifies the attributes of each member, which is equivalent to defining the table structure (field and type). When querying, the database is used. gqlquery () constructs a gqlquery object (which can be used as a set of mymodel objects, such as... in, in gql, "XXX" in "select from XXX" is the class name of the mymodel class "mymodel"), or call the class method mymodel. gql () returns the gqlquery object ("select from XXX" is not required in gql at this time). During insertion, A mymodel object is created and each member is assigned a value, call put () of the object. assign values to the specified Member of the mymodel object and call put (). Call the static method get_by_id () of the mymodel class when deleting the object () or get_by_key_name (), returns a mymodel object and calls the delete object .
IV. 8Django HTML template. In this example, {% if a %} is written. The {% if a = B %} written by me is reported with a syntax error, I checked the Django template document to learn how to write it into {% ifequal a B %}. It is not intuitive. I guess it is wrong. In addition, the system thought of this template is wrong. html is full of {%}, which is a mess, neither HTML nor python, low productivity (but it is better than embedding HTML everywhere in Python code). We should use the template idea of tapestry to minimize HTML intrusion and use the standard HTML editing tool (Dreamweaver) still working normally. Otherwise, the artist mm does not like to participate in your project, and it is difficult for her to cooperate with you. The template System of tapestry is the correct template system with the best idea I have come into contact with. In the future, ESP (easy server pages), which is easy to use, may introduce similar templates.
4.9Set the output encoding to the UTF-8, You can naturally display Chinese: handler. response. headers ['content-type'] = 'text/html; charset = UTF-8'
5. Achievements in learning and practice
The results of these two days are: the whole process of the Getting Started tutorial is completed to form a site crash (there is no editing function currently ).