Prämisse
Schreiben Sie die Prozedur für die Bereitstellung in Heroku unter der gleichen Struktur wie Basisanwendung.
[Verzeichnisstruktur](https://suehiro24.esa.io/posts/11#%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88 % E3% 83% AA% E6% A7% 8B% E6% 88% 90)
Was Sie zu Beginn tun
Trennung von settings.py nach Umgebung
Entwicklung-> root / project-dir / settings / local.py
Production-> root / project-dir / settings / Production.py
Verwaltung von Umgebungsvariablen durch .env * python-dotenv
Richtlinie
Installieren Sie nicht django-toolbelt, installieren Sie jederzeit die erforderlichen Bibliotheken
Umgebung
terminal@Stammverzeichnis der Django-Anwendung
heroku login
# Create app
# Memo:Remote-Repository hinzufügen(folgenden)Wird auch ausgeführt
# git remote add heroku [email protected]:{app-name}.git
heroku create {app-name}
.env
root/.env
SECRET_KEY = ooooooooooooooooooooooooooooooooo
DJANGO_SETTINGS_MODULE = fitmod.settings.local
install ”heroku-config”
terminal
# .Plug-In für env installieren
heroku plugins:install heroku-config
#Reflektiert in Herokus Umgebungsvariablen
heroku config:push
terminal
heroku config:set DJANGO_SETTINGS_MODULE = {app-name}.settings.{settings-file name for product}
Procfile
terminal
install gunicorn
web: python manage.py collectstatic --noinput ; gunicorn note_to_self.wsgi --log-file -
runtime.txt
root/runtime.txt
python-{Python-Version}
# Ex.) python-3.8.0
wsgi.py
terminal
pip install dj-static
root/project/wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from dj_static import Cling #hinzufügen
from dotenv import load_dotenv
load_dotenv('.env')
DJANGO_SETTINGS_MODULE = os.getenv("DJANGO_SETTINGS_MODULE")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', DJANGO_SETTINGS_MODULE)
application = Cling(get_wsgi_application()) # Cling()Hinzufügen
install
#DB für Heroku PostgreSQL-Installation einer Bibliothek, die URLs verarbeitet.
python -m pip install dj_database_url psycopg2
# PostgrSQL Add-bei der Installation
heroku addons:create heroku-postgresql:hobby-dev
usage
settings/production.py
#
import dj_database_url
# Setting PostgreSQL To Heroku
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fitmod',
'USER': 'name',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
}
}
#Unterseite
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
requirements.txt
terminal
pip freeze > requirements.txt
tarminal
# Deploy
git push heroku master
migrate, createsuperuser
terminal
heroku run python manage.py migrate
heroku run python manage.py createsuperuser
requirements.txt
asgiref==3.2.7
dj-database-url==0.5.0
dj-static==0.0.6
Django==3.0.5
gunicorn==20.0.4
psycopg2==2.8.5
python-dotenv==0.13.0
pytz==2020.1
sqlparse==0.3.1
static3==0.7.0
Recommended Posts