Google App Engine Learning and practice

Source: Internet
Author: User
Tags hosting

This weekend to play Google App Engine, write something, is a study notes it. Please correct me if you are not in the wrong place.

LIIGO,2009/04/26 Night, Dalian

Original link: http://blog.csdn.net/liigo/archive/2009/04/26/4127055.aspx

Reprint Please specify source: Http://blog.csdn.net/liigo

One, how do you think of playing Google App engine?

Recently wanted to write a small program to share data between the company's computer and the computer at home. But without ready-made servers and virtual hosts, there is a problem with where the data exists. For this little thing to rent a virtual host, it seems not worth it. Google app Engine (GAE) agrees that users are free to deploy Web applications on Google's servers, which naturally meets my needs.

Two, what is Google App Engine?

Strict definition go to the official site (http://code.google.com/intl/en/appengine/) find it, I (Liigo) popular understanding as, it is a similar virtual host of things, agree you put the written good Web application (Web site), Deployed on its server. For example, now there are all over the network to provide "PHP + MySQL" and "ASP + SQL Server" Virtual hosting services, the average annual fee from hundreds of to thousands of yuan, and Google App engine is equivalent to give you free "Python + Datastore "and" Java servlet/jsp + Datastore "Virtual Hosting services (Datastore is a database provided by Google, the App Engine Datastore is a Schemaless object da Tastore, with a query engine and atomic transactions.). Our program runs on Google's servers, using Google's CPU and bandwidth to enjoy security, flexibility, scalability, and load balancing in Google's excellent network architecture. Google App engine provides free 500M storage for each program, ample CPU (up to 46cpu-hours per day) and bandwidth (up to 10G per day for upload and download traffic), and 5 million hits per month. Enough to handle most project requirements (and, if necessary, to scale up), the average virtual host that provides equivalent performance is expensive. For now, Google App engine only supports Python and Java, and the program will support other programming languages (PHP, Ruby, Perl, ASP, ESP). I (Liigo) personally think that the future of Google APP engine is limitless, will gradually eat into the current virtual host market. At the moment its disadvantage is that it supports only Python and Java, which are clearly not the first choice for web development.

Three, Python, or Java?

Google APP engine now only supports Python and Java, which is a two-choice question. I should have chosen Java from the understanding of programming languages, but given the speed and convenience of development, I finally chose Python that I was not familiar with (or even once rejected). Writing the web with Java is not necessarily the best choice, just like writing a server in easy language.

Four, Google APP engine tour

Follow the Novice tutorial step-by-step, just started to progress smoothly, very quickly successfully deployed the first program, Happy AH.

four. 1 app.yaml *.py and other files can be instantly changed to take effect immediately, without restarting Webserver, very good.

four. 2 library path, very tired ah. In contact with the WebApp (and later Webob, CGI) stuck, reported "Importerror" error, it seems to be unable to find the corresponding Python library (haha, I thought only easy language will prompt "Unable to load the support library"), search for half a day, Finally, by setting the system environment variable Pythonpath to conquer, the value is:

D:/python25/lib;d:/program Files/google/google_appengine;d:/program Files/google/google_appengine/lib/webob

I thought this was the Google App Engine Python SDK installation package negligence, did not correctly set the relevant library path, the people who have just started learning jam for a long day. To say that Java Classpath just started to learn the people are difficult to understand, Python pythonpath, sys.path or not where to go, not to mention, EF is not the same as the introduction of ef_lib_paths. Said more.

four. 3 it cannot be used before the class definition. WebApp the core of the code:

application = WebApp. Wsgiapplication ([('/index ', MainPage)], debug=true)

I deliberately tried, the definition of class MainPage moved to the following line, God, out full screen of the mistake, scared me to change back again. Visible, although it is a scripting language, can not be followed by the temperament. But I really want to write this line at the very beginning of the source file, because it focuses on the structure of the entire program.

four. the letters in the 4 URL are differentiated in uppercase and lowercase. For example: Http://localhost:8080/index written .../index, this is not very good, should be corrected.

four. 5 Python formatted text syntax, and stuck me half a day. There is a sentence in the routine write ("%s"% a), I would like to add a "%s", tried a variety of syntax, write ("%s%s"% A% b), write ("%s%s", A, a, etc.), deeply tortured, but Google also to torture me, do not agree with my search " Python%s "keyword, and later found the correct answer by searching for" python format string ": Write ("%s%s "% (A, b)). Oh, the joy of exploration.

four. 6 text to Integer, with int () function. Delete a post based on an ID, first get the text form of the ID (self.request.get (' id ')), first turn 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, to search for half a day to find the int () this function. C + + words, I know to use Atoi (), Java, I know to use Integer.parseint (); Delphi, I know with strtoint (); Easy language, I know to use "to the whole number ()"; EF words, I know with "text class. to integers () But Python, I'm searching for a half-day talent to find Int ().

four. 7 Google's database datastore. It is not a traditional relational database, but an object database; it does not support standard SQL, but has similar gql. Use in Python: First define a inherit from DB. The Model class (MyModel), which specifies the member properties, is equivalent to defining the table structure (field and its type), and when queried, by DB. Gqlquery () Constructs a Gqlquery object (which can be used as a collection of MyModel objects, such as "XXX" in the "Select from XXX" In the For ... in,gql, which is the class name "MyModel" of the MyModel Class), or by calling the class method Mymodel.gql () to return the Gqlquery object (at which point the "Select from XXX" section is not required); when inserting, an MyModel object is instantiated, the members are assigned values, and the object's put () is called; Assign a member assignment to a MyModel object, call put (), delete, call the MyModel class static method get_by_id () or Get_by_key_name (), return a MyModel object, and call Delete () of the object.

four. 8 Django HTML template. In the demo sample there is {% if a%} in the notation, I tiger, write out {% If a = b%} is reported to have a syntax error, checked the Django template document only know to write {% ifequal a B%}, not intuitive ah, I guess wrong. In addition, feel this template system thinking has a problem, the HTML is flooded with {percent}, a mess, neither HTML nor python, productivity is not high (but always more than in Python code embedded HTML better); Should learn from tapestry's template ideas, There is minimal intrusion into HTML, so that the standard HTML Editing tool (DreamWeaver) still works, otherwise art mm is not interested in participating in your project, she is very difficult to work with you. Tapestry's template system is the best idea I've ever had with the right templating system, and future-prone ESP (easy Server Pages) may introduce similar templates.

Four. 9 The output code is set to UTF-8, it can be very natural to display Chinese: handler.response.headers[' content-type '] = ' text/html; Charset=utf-8 '

Five. The results of learning and practice

The results of these two days are: finished the whole process of the novice tutorial, the formation of the website http://liigotemp.appspot.com/; wrote a simple applet to form a website http://liigoshared.appspot.com/ (temporarily no editing function).

Google App Engine Learning and practice

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.