A django heroku project template based on https://github.com/heroku/heroku-django-template enriched with the most needed django features and packages.
Run this from your terminal (please ensure that you have Ruby installed):
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
Login into Heroku from shell with your heroku credentials (you can sign up for free here)
heroku login
-
Clone this project
git clone git@bitbucket.org:Dosdos/djangoheroku.git
-
Create your venv working environment: Pycharm > Settings > Project Interpreter > (Coil icon) > Create VirtualEnv
-
Set up grunt, install bower components and use grunt watch
- Move to etc folder
- Install grunt modules (make sure you have
node.js
andnode package manager
installed) - Install bower components
- Launch grunt default: it will automatically compile every less file and js file, preen bower components and check for js errors thanks to jshint
cd etc
sudo npm install
bower install
grunt
-
Add ENV='prod' variable in heroku
heroku config:set ENV='prod'
-
Deploy app to heroku
Launch grunt watch: it's a watcher that keeps listening and compiles less and compresses js file when a file is changed
grunt watch
Please note that to store env variable in local machine is necessary to add them to the venv activate file in order to use them while venv is running. Just add to activate file
export SECRET_KEY="here_the_diango_secret_key"
First check the remotes of the project
git remote --v
If heroku
is already among your git remotes, but it is not pointing to the right application, remove the heroku
remote
git remote remove heroku
Add your heroku app to git remotes
heroku git:remote -a <app_name>
Deploying your code to heroku is done through git
git push heroku master
Note: make sure your local master
branch is always aligned with origin master
. If not aligned, when pushing to heroku master
, heroku blocks the push launching an error.
If this was your first deploy we need to set up the db. Heroku allows to run commands through its toolbelt run
command.
-
(Optional) Syncdb
heroku run python manage.py syncdb
-
Migrate
heroku run python manage.py migrate
-
(Optional) Create additional super user
heroku run python manage.py createsuperuser
Note: to review database coordinates and status use heroku pg
command
-
Access heroku database from shell (please, make sure you have installed Postgres locally)
heroku pg:psql
heroku open
Allows to see the application status, if it's running or sleeping, if deployment was successful
heroku ps
Warning! Setting up a higher than 1 number of dynos may cause the service to be not free anymore
heroku ps:scale web=1
heroku run python manage.py shell
If you are not using an external logging service (aka Logentries or Papertrail) heroku logs come in handy
heroku logs --tail
Note: there is a free logentries plugin for heroku that eases the process to connect logentries with your heroku app
The example is Papertrail addon, a logging service that allows to store logs with an higher size and time retention than the heroku 1500 log entries limit
-
Add addon
heroku addons:create papertrail
-
Check list of active addons
heroku addons
-
Open logs in shell
heroku addons:open papertrail
Heroku allows to store configuration variables, such as encryption keys or external resource addresses in config vars (source).
-
Set a new configuration variable
heroku config:set TIMES=2
-
Review all configuration variables
heroku config