- 2014-08-03: virtualenvwapperの設定を修正
- MacOSX10.7.4
- python2.7.3
- GoogleAppEngineLauncher.app 1.6.5
- virtualenv==1.7.1.2
- virtualenvwrapper==3.3
- django==1.3
Install
for MacPorts and Pip
sudo port install py27-python sudo port install py27-pip pip-2.7 install virtualenv pip-2.7 install virtualenvwrapper
bashrc
MacPorts でインストールした場合
export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/:$PATH if [ -f $(which virtualenvwrapper.sh) ]; then # export VIRTUALENVWRAPPER_PYTHON=python # export VIRTUALENVWRAPPER_VIRTUALENV=virtualenv # export VIRTUALENVWRAPPER_VIRTUALENV_CLONE=virtualenv-clone # export WORKON_HOME=$HOME/.virtualenvs # default # export VIRTUALENVWRAPPER_SCRIPT=virtualenvwrapper.sh source virtualenvwrapper.sh fi
Django in virtualenv
mkvirtualenv django13 (django13) $ pip-2.7 install django==1.3 (django13) $ django-admin.py --version 1.3
activate, deactivate
(django13) $ deactivate #抜ける $ workon django13 #入る (django13) $
Django in GAE
Google App Engine の Django を使ってみる
New Application
GoogleAppEngineLauncher.app で アプリ作成
- gae_django
(django13) $ cd gae_django (django13) $ django-admin.py startproject mysite
- app.yaml
application: mysite version: 1 runtime: python27 api_version: 1 threadsafe: yes handlers: - url: /favicon\.ico static_files: favicon.ico upload: favicon\.ico - url: .* script: main.app libraries: - name: django version: "1.3"
- main.py
import os # specify the name of your settings module os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' import django.core.handlers.wsgi app = django.core.handlers.wsgi.WSGIHandler()
Deploy
GoogleAppEngineLauncher.app で Deploy してみる
*** Running appfg.py with the following flags: --no_cookies --email=xxxxxxxx@gmail.com --passin update Application: mysite; version: 1 Host: appengine.google.com Starting update of app: mugirice, version: 1 Getting current resource limits. Scanning files on local disk. Error 400: --- begin server output --- The 'python27' runtime is only supported for apps using the High Replication Datastore. --- end server output --- Password for xxxxxxxx@gmail.com: If deploy fails you might need to 'rollback' manually. The "Make Symlinks..." menu option can help with command-line work. *** appcfg.py has finished with exit code 1 ***
なぜに?(´・ω・`)
原因発覚 HRD これ原因
GAE で Python2.7 使うとデータストアを High Replication Datastore にする必要があるそうな。
既に旧デフォルトのMaser/Slaveデータストアで作成してる場合は、GAEのサイトで新しくアプリケーションを作らないといけない。
(今現在のデフォルトはHRD)
ちなみにこれ『Pythonプロフェッショナルプログラミング』に載ってた。まだ持ってない人は買うべき。
High Replication (default)
Uses a more highly replicated Datastore that makes use of a system based on the Paxos algorithm to synchronously replicate data across multiple locations simultaneously. Offers the highest level of availability for reads and writes at the cost of eventual consistency for some queries. Note: High Replication Datastore is required in order to use the Python 2.7 and Go runtimes.
データストアを High Replication Datastore で新しくアプリケーション作成してやったら、あっさりデプロイできた(・∀・)b
Memo
GAE + Django はデータベースどうすればいいのかな? Google Cloud SQL か、終了の Django-nonrel? (@CortYuming)
https://twitter.com/CortYuming/status/204227754097524736
GAEの他に