wororo.

djangoHeroku

2017/09/23

Base Django-Heroku

Git should be installed

Virtual Environment

Requirements

1
2
sudo pip install virtualenv
sudo pip install virtualenvwrapper

Create a Virtual Environment

1
$ mkvirtualenv djangoApp

Django

Requirements

1
2
3
4
5
6
7
8
9
10
11
12
$ pip install django
$ pip install python_dotenv
```
## Create Project
``` bash
$ cd djangoApp
$ django-admin.py startproject --template=https://github.com/heroku/heroku-django-template/archive/master.zip --name=Procfile myHerokuProject
$ cd myHerokuProject
$ pip install -r requirements.txt
$ echo "db.sqlite3" >> .gitignore

Remove Secret Key (Using python_dotenv)

1
2
3
$ echo "python_dotenv" >> requirements.txt
$ cd myHerokuProject
$ touch .env

Move SECRET_KEY=key to the .env file (should be in the same folder as settings.py)

Add the following lines to your settings.py:

1
2
3
4
5
6
...
from dotenv import load_dotenv, find_dotenv
...
load_dotenv(find_dotenv())
SECRET_KEY = os.environ.get('SECRET_KEY')
...

Exit directory

1
$ cd ..

Github

Create Github Repo myHerokuProjectGit

1
2
3
4
5
$ git init
$ git remote add origin https://github.com/[githubUsername]/[myHerokuProjectGit].git
$ git add -A
$ git commit -m "django template initial commit"
$ git push -u origin master

Heroku

Requirements

1
2
3
4
$ wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
```
## Create Heroku App

$ heroku login
$ heroku create example-project-name
$ heroku config:set DISABLE_COLLECTSTATIC=1

1
2
3
4
**Heroku Web:** Settings Tab -> Reveal Config Vars -> Add: SECRET_KEY : secret key value
**Heroku Web:** Deploy Tab -> Connect to Github -> Connect -> Enable Automatic Deploys

$ git push heroku master

1
2
3
4
## Commands in Heroku
## Run Local

$ heroku local

1
2
### Migrate on server side

$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate

1
2
### Create Admin on server side

$ heroku run python manage.py createsuperuser
```

CATALOG
  1. 1. Base Django-Heroku
  2. 2. Virtual Environment
    1. 2.1. Requirements
    2. 2.2. Create a Virtual Environment
  3. 3. Django
    1. 3.1. Requirements
    2. 3.2. Remove Secret Key (Using python_dotenv)
  4. 4. Github
    1. 4.1. Create Github Repo myHerokuProjectGit
  5. 5. Heroku
    1. 5.1. Requirements