I wrote the article by referring to the official document below. https://devcenter.heroku.com/articles/getting-started-with-django#declare-process-types-with-procfile
Installation
$ brew install postgresql
Pass the path (~ / .bash_profile)
export PATH=/usr/local/Cellar/postgresql/9.4.1/bin:"$PATH"
Reboot the terminal
** Create and move application management directory **
$ mkdir hellodjango && cd hellodjango
** Build a virtual environment with venv and start it **
$ virtualenv venv
$ source venv/bin/activate
** Download the complete Django-related library **
$ pip install django-toolbelt
** Django project creation **
$ django-admin.py startproject hellodjango .
** Create a Procfile and describe the following contents **
web: gunicorn hellodjango.wsgi --log-file -
** Start local server **
$ foreman start
21:21:26 web.1 | started with pid 5513
21:21:26 web.1 | [2015-05-10 21:21:26 +0900] [5513] [INFO] Starting gunicorn 19.3.0
21:21:26 web.1 | [2015-05-10 21:21:26 +0900] [5513] [INFO] Listening at: http://0.0.0.0:5000 (5513)
21:21:26 web.1 | [2015-05-10 21:21:26 +0900] [5513] [INFO] Using worker: sync
21:21:26 web.1 | [2015-05-10 21:21:26 +0900] [5516] [INFO] Booting worker with pid: 5516
OK if you can access at http://0.0.0.0:5000
$ pip freeze > requirements.txt
** Add the following content to the end of settings.py **
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] = dj_database_url.config()
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
** Rewrite wsgi.py with the following contents **
import os
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")
application = Cling(get_wsgi_application())
** Create a .gitignore file and add the following contents **
venv
*.pyc
staticfiles
** Add to repository **
$ git init
$ git add .
$ git commit -m "my django app"
** Create repository on heroku **
$ heroku create
** Deploy application to heroku **
$ git push heroku master
** Set the number of dyno **
$ heroku ps:scale web=1
** Check from browser **
$ heroku open
OK if the following screen appears!
Recommended Posts