First than all let's start by setting the all environment by downloading the Python SDK from code.google.com. For Windows just install the ".msi" executable and for Linux just extract the ".zip" in your "home" folder. Don't forget to install Python on Windows.
Aptana is based on the Eclipse framework and therefore is possible to install many Eclipse plugins on it. The plugin that allow coding Python on Aptana (and Eclipse) is Pydev. Once you open Aptana for the first time select the Pydev perspective.
Let's specify the version of Python to Pydev in Aptana. Select "Window -> Preferences -> Pydev -> Intrepeter - Python". Click on the "Auto Config" button or select the path of your Python interpreter on the "New ..." button.
Lets start by creating a new Pydev Google App Engine Project. Select "File -> New -> Project -> Pydev -> Pydev Google App Engine Project".
Make sure to select the correct version of Python for the project and the path for the Google SDK. Look at the images below.
Now we have the development environment complete. I will assume that you have created an application on https://appengine.google.com/. For the next example I will use my own app called djangoabdel (I called like this because I like Django a lot!)
When I started reading the documentation of GAE it was evident that there is a lot of freedom for create your own framework. So I will show my way but you can innovate or use any pure Python framework (Django?). Lets take a look at this image:
Here I have:
- main.py - This is the start point of the whole application.
- appengine_config.py - At the top level of your project is automatically imported by
google.appengine.ext.webapp.util.run_wsgi_app()to add middlewear to webapp applications. This is how I specify Django version (1.0, 1.1 or 1.2). Take a look at.
- app.yaml - The heart of the app configuration.
- controllers - python package that contains all the controllers or business scripts of our application.
- models - python package that contains all the models or Entities of our application.
- libs - python package that contains all the third party libraries.
I will create a post for explain more detailed the different parts.
One thing that happened to me while creating this way of development was a problem trying to import the controllers, libs, models to the main.py file. The solution is pretty simple, just add this to the __init__.py file in the package folder:
import os, sys
path = os.path.abspath(".")
Even if sometimes you have trouble trying to import a package just restart the test server. Just keep this in mind (Oh, you will!).
Now lets create a "Run" configuration so we can run our development server. Go for "Run -> Run Configurations...". Here double click on "Pydev Google App Run" and set a name to this configuration and the at "Main Module" point to "dev_appserver.py" file. This file is in the SDK installation files.
The last of the configuration is click on the "Arguments" tab and on "Program Arguments" add the path to your application folder.
Now click on "Apply" button and then on "Run" button for run the app. Now all the messages of the application will appear on the 'Console" tab. Here you can stop the development server too.
Now that the "Run" configuration is created, the "Debug" configuration is created automatically. Take a look at the short-cut buttons.
Just remember that for debugging set your break points.
While you will be coding you'll enjoy the auto-complete behaviour of Pydev (Ctrl + Space Bar). But the most I like is the Django Template Editor for the GAE template files. When opening a html file from the "Pydev Package Explorer" do a right click "Open with ->" and select "HTML.Templates Django Editor (Aptana)". GAE takes advantage of the Django template tags and filters, so lets do the same on this editor.
The last part is upload our app to Google so that's easy as do a right click on our project "Pydev: Google App Engine -> Upload".
Thank you for your time.