-
Notifications
You must be signed in to change notification settings - Fork 0
Depolying Django
Create a project with preconfigured settings for deployment on heroku
django-admin startproject --template=https://github.com/heroku/heroku-django-template/archive/master.zip --name=Procfile mysite
Procfile
web: gunicorn myproject.wsgi --log-file -
Create a new heroku app from the command line
heroku create appname
For an existing git
repo and existing app, use this command to create an appropriate remote to push to heroku for deployment (if automatic push deployment is not configured)
heroku git:remote -a appname
Deploy to heroku with
git push heroku master
Setup remote database (migrate a local one with loaddata
, see above)
heroku run python manage.py makemigrations
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
Run local server Read more
heroku local web
One-off dynos (remote terminal)
heroku run [bash|python]
heroku run python manage.py shell
Check/manage resources
heroku ps
heroku ps:scale web=0
heroku ps:scale web=1
View logs
heroku logs --tail
Open app
heroku open
View releases and rollback
heroku releases
heroku releases:rollback v2
Environment Variables read more
heroku config
heroku config:set DJANGO_DEBUG=''
Generate a new SECRET_KEY
heroku config:set SECRET_KEY=$(python -c 'import random; import string; print("".join([random.SystemRandom().choice("{}{}{}".format(string.ascii_letters, string.digits, string.punctuation)) for i in range(50)]))')
Required dependencies to deploy on heroku:
pip install gunicorn dj-database-url whitenoise psycopg2
django-toolbelt
is a meta package requesting the above.
Create dependencies list
pip freeze > requirements.txt
Install dependencies list
pip install -r requirements.txt
- Set up Virtualenv
-
Set environmment variables
- For the web app, set it inside its WSGI configuration file.
If DEBUG=False
, remember to run python manage.py collectstatic
.
- https://cloud.google.com/sdk/docs/
- https://cloud.google.com/python/django/
- https://cloud.google.com/python/django/flexible-environment
Need to buy EC2 for compute, S3 for storage, and Amazon RDS for PostgreSQL
This is a collection of tips and reminders for me on how to do things. What is documented here is derived from personal experience and from all over the web (some instruction or information has been copied verbatim). Original sources are provided for some of them. I have built these up over time so it has not been documented properly until now.