2012年10月15日 星期一

GAE - Use Django Framework - from scrach 1

Pre-requsite

  1. Install eclipse 3.8 Platform Runtime Binary
    http://download.eclipse.org/eclipse/downloads/drops/R-3.8-201206081200/
  2. Install Aptana Studio 3 eclipse plugin : http://download.aptana.com/studio3/plugin/install
  3. Install Google App Engine
  4. Install Python 2.7.2, 
  5. Install Django 1.3, don't install 1.4.x that still not supported by GAE untill now.
  6. Download Django-nonrel engine (djangoappengin)
  7. Add %python2.7_home%\Scripts to path (that we need to access dango-admin.py)
Create a new test project
  1. Under eclipse workspace directory run : django-admin.py startproject gdjtest
  2. New a 'PyDev Google App Engine Project' from eclipse, named 'gdjtest'
  3. New a GEA configuration file under project root : app.yaml, with content as below
    application: gdjtest
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: yes

    libraries:
    - name: django
    version: 1.3

    - url: /.*
    script: djangoappengine.main.application
  4. Copy djangoappengin from django-nonrel to project root directory
  5. Start up GAE Django server : project submenu:[Run As][PyDev:Google App Run]
  6. Use browser to test : http://localhost:8080/
  7. If success, got the page response as below :

    It worked!

    Congratulations on your first Django-powered page.

    Of course, you haven't actually done any work yet. Here's what to do next:
    • If you plan to use a database, edit the DATABASES setting in settings/settings.py.
    • Start your first app by running python settings/manage.py startapp [appname].
    You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

Error Debugging

  1. App server startup fail : No URLMap entries found in application configuration
    app.yaml loss handlers section
    handlers:
    - url: /.*
    script: djangoappengine.main.application
  2. ImportError: No module named django.conf
    app.yaml lose django libraries
    libraries:
    - name: django
    version: 1.3
  3. ImportError: No module named gdjtest.urls
    Modify settings.py, find line ROOT_URLCONF = 'gdjtest.urls' and change to ROOT_URLCONF = 'urls'

Complete app.yaml for Django on GAE:

application: optionwatch
version: 1
runtime: python27
api_version: 1
threadsafe: yes

builtins:
- remote_api: on

inbound_services:
- warmup

libraries:
- name: django
version: 1.3
- name: lxml
version: latest

handlers:
- url: /_ah/queue/deferred
script: djangoappengine.deferred.handler.application
login: admin

- url: /_ah/stats/.*
script: djangoappengine.appstats.application

- url: /media/admin
static_dir: django/contrib/admin/media
expiration: '0'

- url: /.*
script: djangoappengine.main.application


沒有留言: