Project: Get Django 1.5 & Google App Engine to play nice.
Date: 2-Jan-2015
Goal: Create a reasonable development environment with the most current version of Django to run on Google App Engine.
Status: Failed
Setup
- Install Google Cloud SDK
- Create app engine project on the google developer console
Django
App engine seems to only support django 1.5 right now, which is unfortunate.
What is more fortunate, is that they provide a starting template:
$ git clone https://github.com/GoogleCloudPlatform/appengine-django-skeleton.git
Put all that into a ~/root/projects/<project-id>. Remove the .git directory, it will just get in the way.
Create a virtual environment
cd ~/root/development/env
python2.7 -m virtualenv <project-id>
. <project-id>/bin/activate
Set up Pydev
Open Eclipse, start a new pydev App Engine project from existing sources, pointed at ~/root/projects/<project-id>. In eclipse’s preferences, add a new python interpreter at ~/root/development/env/<project-id>/bin/python, and set it as the default for the project.
Configure the app.yaml
GAE uses the app.yaml file for project configuration. The skeleton provides one, edit it to match your & whatnot.
Set up python
Getting everything into the right places in the python path seems to be a bit harder than necessary.
Follow the instructions in the appengine-django-skeleton readme (run build.sh). First, make sure you deactivate your virtual environment ($ deactivate). build.sh will install various dependencies in the current directory.
I’m not sure what modifications have been made to django, but manage.py runserver is supposed to use the dev_appserver.py to run. This doesn’t seem to work out of the box.
Path Hacks
The GoogleAppEngineLauncher program installed symlinks to appengine binaries into /usr/local, but didn’t seem to do anything with the PYTHONPATH.
I’m not sure that it would it necessarily know how to change the PYTHONPATH, since it doesn’t know what interpreter I’m using. On the other hand, it’s also rude to modify my system python, but the documentation also seems to think that installing is all you need to do. Maybe it has something to do with me not putting GoogleAppEngineLauncher.app into /Applications, but I never put anything in there since permissions are becoming weird in that folder (it seems to belong to Apple and their App store now, not to me).
So, to help it out, manually create symlinks in the site-packages directory so python can find what it needs. (I would prefer .egg-link files, but these are just modules, not eggs so that won’t work).
cd ~/root/development/env/<project-id>/lib/python2.7/site-packages
ln -s /Users/seth/root/development/sdk/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google
ln -s /Users/seth/root/development/sdk/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/[^_]*.py .
Now that I’m looking at the files in that directory, it seems that there’s a file called _python_runtime.py that seems to fix up the path. But it also adds a ton of other stuff (everything in GoogleAppEngine-default.bundle/.../lib) to the path too. It might make sense to revisit that, maybe import it in sitecustomize.py or something.
Getting it running
The django app engine skeleton seems to be out of sync with the app engine SDK :(
Supposedly, running python manage.py runserver should work, but in my case, it says:
Traceback (most recent call last):
...
Exception: Could not get appid. Is your app.yaml file missing? Error was: cannot import name dev_appserver
The standard way of running a GAE app locally does seem to work though:
dev_appserver.py app.yaml
After that, hit http://localhost:8080, and you’ll see the welcome page.
Results
Hmm, it also seems that this gives you django 1.4, not 1.5 as I thought it would. Now that I’ve realized this, I see that the last commit on this project is about a year ago, November 15, 2013.
Also, the documentation and current SDKs don’t match anymore. This makes me think that I’m going to continue to run into problems with GAE and djangoappengine. Later today or tomorrow I’ll try a different approach, this doesn’t work.
On the plus side, I did figure out a nice way to publish Markdown documents on blogger (via stackedit.io).
No comments:
Post a Comment