Dirty Guide to AppEngine Remote Console with Django on OSX

December 20th, 2013  by Blaine Garrett

Google AppEngine has a super cool command line tool to manipulate the data on your appspot. However, the docs are a bit confusing at first, especially if you are using django. Here are a couple tips to get it working. Existing Docs Google's documentation appears to be in 2 spots. Doing a google search produces this article from 2009 as its first hit. Slightly more up to date, but containing basically the same info, is this doc. Step 1: Before we begin Follow either of the links above to enable the remote api for your appspot in the app.yaml and deploy your app. Also, it is worth noting that I am working on OSX Mavericks and using Textmate as my editor of choice. In the command below to edit your bash profile, replace mate with whatever text editor you use that works with the command line. Step 2: Ensure $GAE_SDK_ROOT is Set In your terminal, enter: [source lang="python"]echo $GAE_SDK_ROOT[/source] If you do not get a value skip to Step 3, otherwise, we need to set this Environment Variable. First, lets find the remote_console. [source lang="python"]locate remote_api_shell[/source] You may get multiple files. The latest for me is: /Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/remote_api_shell.py. Yours may be slightly different. If you do not have one, re-run the installer for appengine launcher. Copy the path to the directory to the remote_api_shell Next we need to set the environment variable in our bash profile. Here is a good article on how to set it up for mac. Here is what I did: [source lang="python"]mate ~/.bash_profile[/source] In your text editor enter this line: [source lang="python"]export GAE_SDK_ROOT=<the full path to the folder containing remote_api_shell.py>[/source] Save the file. Next reopen your terminal or reload your environment via: [source lang="python"]source ~/.bash_profile[/source] Finally, test to see if the change stuck: [source lang="python"]echo $GAE_SDK_ROOT[/source] If so, continue to step 3. Step 3: Run the remote console Now we can pick up where the Google Appengine Docs start: [source lang="python"]$GAE_SDK_ROOT/remote_api_shell.py -s <your_app_id>.appspot.com[/source] If you get prompted with a email/pw login, use the same credentials you would use for deploy your app with appcfg. We're IN! Step 4: Loading Django bits If you have any sort of dependencies on django in your app, you will typically get the follow error when trying to import your models: EnvironmentError: Environment variable DJANGO_SETTINGS_MODULE is undefined. It is unclear to me what exactly is going on and why the app.yaml is not being used to load django. So we need to load up django. We can do this using: [source lang="python"]import os, sys from google.appengine.dist import use_library use_library('django', '1.2') # Replace with whatever your django version is os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'[/source] Now if you try to import your models, you should be golden. Leave me a comment if you ran in to issues with this, especially if you have updated info to add to the post. Thanks!

👍