django on heroku
Black Elephants
https://devcenter.heroku.com/articles/getting-started-with-django
http://www.django-rest-framework.org/tutorial/quickstart/
http://marcantoinelemieux.com/blog/posts/2013/01/13/how-to-build-a-basic-timeserver-using-django-and-heroku
https://github.com/tomchristie/rest-framework-tutorial/blob/master/requirements.txt
- mkdir <project name>
- cd <project name>
- virtualenv venv
- source venv/bin/activate
// this will activate virtual environment. verify prompt prefixed with (venv) - pip install django-toolbelt djangorestframework
// you will probably get compile warnings. safe to ignore - django-admin.py startproject <project name> . <-- don't forget the dot
- cd <project name>
- django-admin.py startapp <app name>
- cd ..
- echo 'web: gunicorn <project name>.wsgi --log-file -' > Procfile
- foreman start // verify at http://localhost:5000
- pip freeze > requirements.txt
settings.py
// add after DATABASES = {} import dj_database_url DATABASES['default'] = dj_database_url.config() SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') ALLOWED_HOSTS = ['*'] // modified // add after BASE_DIR STATIC_ROOT = 'staticfiles' STATICFILES_DIR = ( os.path.join(BASE_DIR, 'static'), ) // add to INSTALLED_APPS 'rest_framework' REST_FRAMEWORK = { 'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAdminUser',), 'PAGE_SIZE': 10 }
wsgi.py
// add after from django.core.wsgi from dj_static import Cling application = Cling(get_wsgi_application()) // modified
- touch .gitignore
- open .gitignore
.gitignore
venv *.pyc staticfiles .idea // pycharm ide
- git init
- git add .
- git commit -m "Initial commit"
- heroku create
- git push heroku master
- heroku run python manage.py migrate
- heroku run python manage.py createsuperuser
// prompts for username, email, pw - heroku open