1) Google App Engine Registration
If you have already registered yourself with GAE then skip this step otherwise just click on the link https://appengine.google.com/ and register yourself for GAE.You can create up to 10 applications. Click on the Create Application button to create a new application. The application Id that you choose have to available as it creates a sub-domain for the appspot.com with that name so that you can access your application later using http://{your_app_Id}.appspot.com
2) Setup Eclipse for Python programming
Depending on what your current setup is you may have to download one or more of the following, Python Interpreter, Eclipse, Java and PyDev plugin for Python Eclipse development. If you already have this setup done just skip over to the next step otherwise follow this link: Python beginner Tutorial using Eclipse PyDev PluginImportant Note: The above tutorial downloads the Python 3.2 version, in your case download the Python 2.7 version as GAE currently doesn't support version 3.2
3) Download and Install Google App Engine SDK for Python
In case of Windows you can use the native installer file GoogleAppEngine-1.7.2.msi. Here is the link https://developers.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python4) Hello World Project using Eclipse
Create a new project in Eclipse. File -> New -> Project. Search for PyDev and Select PyDev Google App Engine Projectapplication: my-sample-code version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.pyhelloworld.py is our Web Application. It just prints hello world on the web page.
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()
5) Run our Hello World Application Locally
Right click on the helloworld.py file -> Run As –> Run Configuration. Create a new PyDev Google App Run launch configuration and name it Run Python Hello World. Also specify the Main Module as dev_appserver.pyIt is available under the GAE installed directory, you have to type the path for some reason the Browse functionality doesn't work.
--port=8081 ${project_loc}/src
6) Modify our Hello World Application
The default template created uses webapp. We are going to changes that to use webapp2. webapp2 is part of the Python 2.7 runtime since App Engine SDK 1.6.0. webapp2 is a simple. It follows the simplicity of webapp, but improves it in some ways: it adds better URI routing and exception handling, a full featured response object and a more flexible dispatching mechanism.Copy the following source into your helloworld.py
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): myPage = """ <html> <body> <form action="/hello" method="post"> <div> <h2>Sample Hello World Application using GAE and Python</h2><br/> <input type="text" name="yourname" size="30" maxlength="30"></input> </div> <div> <input type="submit" value="Submit My Form"> </div> </form> </body> </html> """ self.response.out.write(myPage) class Hello(webapp2.RequestHandler): def post(self): yourname = self.request.get('yourname') self.response.out.write(""" <html> <body> <div> """) self.response.out.write("<h2>Hello World - " + yourname + "</h2>") self.response.out.write(""" </div> </body> </html> """) app = webapp2.WSGIApplication([('/', MainPage), ('/hello', Hello)], debug=True)Update you application configuration file app.yaml with the following code
application: my-sample-code version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /.* script: helloworld.app libraries: - name: webapp2 version: "2.5.1"There is no need to Run anything again. Just go the browser and hit refresh and you should see the changes to your application.
7) Deploy your application to Google App Engine
Right click on the helloworld.py file -> Run As –> Run Configuration. Create a new PyDev Google App Run launch configuration and name it Deploy Python Hello World. Also specify the Main Module as appcfg.py06:02 PM Host: appengine.google.com 06:02 PM Application: my-sample-code; version: 1 06:02 PM Starting update of app: my-sample-code, version: 1 06:02 PM Getting current resource limits. Email: {enter email here} Password for {email}@gmail.com: {enter password here} 06:02 PM Scanning files on local disk. 06:02 PM Cloning 2 application files. 06:02 PM Uploading 2 files and blobs. 06:02 PM Uploaded 2 files and blobs 06:02 PM Compilation starting. 06:02 PM Compilation completed. 06:02 PM Starting deployment. 06:03 PM Checking if deployment succeeded. 06:03 PM Will check again in 1 seconds. 06:03 PM Checking if deployment succeeded. 06:03 PM Will check again in 2 seconds. 06:03 PM Checking if deployment succeeded. 06:03 PM Will check again in 4 seconds. 06:03 PM Checking if deployment succeeded. 06:03 PM Deployment successful. 06:03 PM Checking if updated app version is serving. 06:03 PM Will check again in 1 seconds. 06:03 PM Checking if updated app version is serving. 06:03 PM Will check again in 2 seconds. 06:03 PM Checking if updated app version is serving. 06:03 PM Will check again in 4 seconds. 06:03 PM Checking if updated app version is serving. 06:03 PM Completed update of app: my-sample-code, version: 1Your application is now deployed to http://{your_app_Id}.appspot.com
No comments:
Post a Comment
NO JUNK, Please try to keep this clean and related to the topic at hand.
Comments are for users to ask questions, collaborate or improve on existing.