序章:
Herokuクイック スタート ガイドで Django を開始するに従っています。
virtualenv とプロジェクトの操作について、 Two Scoops of Django の本の哲学を適用するつもりです。Audrey RoyとDaniel Greenfeld (著者) は、すべての環境を 1 つのディレクトリに配置し、すべてのプロジェクトを別のディレクトリに配置することを好みます。
また、管理コマンドによって生成されたものを git リポジトリ ルートとして機能する別のディレクトリ内に配置するという、 Two Scoops of Django の本の哲学を適用するつもりです(別名、3 層アプローチ)。
django-admin.py startproject
最高レベルのレイアウト:
repository_root/
django_project_root/
configuration_root/
ローカル:
OS X 10.8.4
pip==1.4.1
virtualenv==1.10.1
virtualenvwrapper==4.1.1
wsgiref==0.1.2
.bashrc には以下が含まれます:
export WORKON_HOME=$HOME/Envs
export PROJECT_HOME=$HOME/Projects
~/環境
~/プロジェクト
hellodjango_venv の内部:
Django==1.5.2
dj-database-url==0.2.2
dj-static==0.0.5
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.1
static==0.4
ターミナルから:
mac-pol:~ oubiga$ mkdir -p Projects/hellodjango_rep/hellodjango
mac-pol:~ oubiga$ cd Projects/hellodjango_rep/hellodjango
mac-pol:hellodjango oubiga$ mkvirtualenv hellodjango_venv
New python executable in hellodjango_venv/bin/python2.7
Also creating executable in hellodjango_venv/bin/python
Installing Setuptools..................................
...
..................................................done.
(hellodjango_venv)mac-pol:hellodjango oubiga$ pip install django-toolbelt
...
Successfully installed django-toolbelt django psycopg2 gunicorn dj-database-url dj-static static
Cleaning up...
(hellodjango_venv)mac-pol:hellodjango oubiga$ django-admin.py startproject hellodjango .
(hellodjango_venv)mac-pol:hellodjango oubiga$ touch Procfile && open Procfile
プロファイルを編集:
web: gunicorn hellodjango.wsgi
プロセスを開始します。
(hellodjango_venv)mac-pol:hellodjango oubiga$ foreman start
01:30:37 web.1 | started with pid 638
01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Starting gunicorn 18.0
01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Listening at: http://0.0.0.0:5000 (638)
01:30:37 web.1 | 2013-09-04 01:30:37 [638] [INFO] Using worker: sync
01:30:37 web.1 | 2013-09-04 01:30:37 [641] [INFO] Booting worker with pid: 641
CTRL+C
ここまでは順調ですね。
現時点で私のプロジェクトツリーは次のとおりです。
~/Projects/
hellodjango_rep/
hellodjango/ cwd
manage.py
Procfile
hellodjango/
__init__.py
settings/
urls.py
wsgi.py
私のVirtualenvsツリーは次のとおりです。
~/Envs/
get_env_details
initialize
postactivate
postdeactivate
postmkproject
postmkvirtualenv
postrmproject
postrmvirtualenv
preactivate
predeactivate
premkproject
premkvirtualenv
prermproject
prermvirtualenv
hellodjango_venv/
bin/
include/
lib/
しかし、三層アプローチを覚えていますか?どうすれば達成できますか?
後で hellodjango_rep/ に少なくとも .git、.gitignore、requirements.txt が含まれると確信しています。
リサーチ:
#django IRC チャンネルで、Jacob Kaplan-Mossは次のように答えました。
...Procfile は git リポジトリの最上位にある必要があります...
Heroku のエンジニアであるNeil Middletonは、SO で「Procfile は Heroku で型を宣言します -> (none)」という質問に答えました。
...Procfile は、Heroku にプッシュされる git リポジトリのルートにある必要があります...
Heroku デベロッパー センターから:
...プロセス タイプは、アプリのルートに配置された Procfile という名前のファイルを介して宣言されます...
最初の試みとして:
Profile を 1 つ上のフォルダー レベルに移動します。
(hellodjango_venv)mac-pol:hellodjango oubiga$ cd ..
現時点で私のプロジェクトツリーは次のとおりです。
~/Projects/
hellodjango_rep/ cwd
Procfile
hellodjango/
manage.py
hellodjango/
__init__.py
settings/
urls.py
wsgi.py
プロセスをもう一度開始します。
(hellodjango_venv)mac-pol:hellodjango_rep oubiga$ foreman start
ImportError : No module named hellodjango.wsgiが発生します
デバッグ:
ImportError から来ているようです/Users/oubiga/Envs/hellodjango_venv/lib/python2.7/site-packages/gunicorn/util.py
def import_app(module):
parts = module.split(":", 1)
if len(parts) == 1:
module, obj = module, "application"
else:
module, obj = parts[0], parts[1]
try:
__import__(module) # <-- line 354
except ImportError:
if module.endswith(".py") and os.path.exists(module):
raise ImportError("Failed to find application, did "
"you mean '%s:%s'?" % (module.rsplit(".", 1)[0], obj))
else:
raise
...
hellodjango.wsgi という名前のモジュールはありません
2 回目の試行として:
Procfile は前のレベルに戻ります。Profile と manage.py が再び一緒になりました。
(hellodjango_venv)mac-pol:hellodjango_rep oubiga$ foreman start
なぜERROR: Procfile does not exist.
それが起こるのかは明らかです。
仮説:
Django のドキュメントから:
...manage.py は、Django プロジェクトごとに自動的に作成されます。manage.py は django-admin.py の薄いラッパーであり、django-admin.py に委譲する前に次の 2 つの処理を行います。
- プロジェクトのパッケージを sys.path に配置します。
- プロジェクトの settings.py ファイルを指すように DJANGO_SETTINGS_MODULE 環境変数を設定します...
問題がこれに関連しているかどうかはわかりません。
そう:
Procfile と manage.py ファイルを異なるフォルダー レベルに置くことは可能ですか?
このアプローチの何が問題なのですか?
前もって感謝します。