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
|
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
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 ```
|
$ 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
```