https://devcenter.heroku.com/articles/getting-started-with-django
ここを見ておくのがいい。 requirements見るのがいい。 pipで入れるものを記載しておくべき。
間違って
pip install Django==Django-1.7
と書くのではなく、
Django==Django-1.7
でいい。
HOSTNAMEについて
Rubyに負けるな!HerokuでPython(Django)動かす方法 - Qiita ここを見ると何の説明もなしに、hostnameというのがあるが、
python - Accessing Heroku's url root in Django settings.py - Stack Overflow このサイトを参考に、socketを使ってとるようにした。
hoge-MacBook-Pro.local
みたいな感じにとれる。
import socket
HOSTNAME = socket.gethostname()
URL_ROOT = HOSTNAME
if 'local' in HOSTNAME:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
else:
import dj_database_url
DATABASES = {
'default': dj_database_url.config()
}
あと、何かと問題なのはDjango 1.7のせいかもしれないが、
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'))
で
DeprecationWarning: The TEMPLATE_DIRS setting must be a tuple. Please fix your settings, as auto-correction is now deprecated. self._wrapped = Settings(settings_module)
from os.path import join
TEMPLATE_DIRS = (
join(BASE_DIR, 'templates'),
)
にした。
heroku run python manage.py syncdb
のコマンドをすることが必須。
下のログが出る。これはなに?
Running `python manage.py syncdb` attached to terminal... up, run.1760
System check identified some issues:
WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
System check identified some issues:
WARNINGS:
?: (1_6.W001) Some project unittests may not execute as expected.
HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
settings.pyに
STATIC_ROOT = 'staticfiles'
がないと
git push heroku master
コマンドで失敗する。
syncdbのあとは
heroku restart
を行うのがいいようだ。
これやらないとダメみたい
heroku ps:scale web=1
ちなみにProcfileファイルが必要。直下に。
web: gunicorn --env DJANGO_SETTINGS_MODULE=jam.settings jam.wsgi --log-file -
のように書いた。※ jamは随時変更する。 ほかのサイトには"web: "が省略されててハマった。
jam.wsgiを同じ所においた。※ jamの部分は任意だと思う。僕も今度変える。
```` from django.core.wsgi import get_wsgi_application from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application() application = DjangoWhiteNoise(application)