LoginSignup
1
2

More than 5 years have passed since last update.

Django + GAE or Heroku (deploy)

Last updated at Posted at 2019-01-05

Reference

App Engine スタンダード環境での Django の実行

Google App Engine のドキュメント

Getting Started on Heroku with Python

Git Documentation

1. GAE

/[project_name]/settings.py

ALLOWED_HOSTS = ['*']

/[project_name]/wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dj_project_1.settings')

application = get_wsgi_application()

/app.yaml

# [START django_app]
runtime: python37

handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
  static_dir: static/

# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
  script: auto
# [END django_app]

/main.py

from [project_name].wsgi import application

# App Engine by default looks for a main.py file at the root of the app
# directory with a WSGI-compatible object called app.
# This file imports the WSGI-compatible object of your Django app,
# application from mysite/wsgi.py and renames it app so it is discoverable by
# App Engine without additional configuration.
# Alternatively, you can add a custom entrypoint field in your app.yaml:
# entrypoint: gunicorn -b :$PORT mysite.wsgi
app = application

/requirements.txt

Django==2.1.3

deploy

#local
virtualenv ./envs/django
source ./envs/django/bin/activate

pip install -r requirements.txt
gcloud app deploy

2. Heroku

/[project_name]/settings.py

import django_heroku

django_heroku.settings(locals())

# delete the above for local testing
# python manage.py runserver

Procfile

web: gunicorn [project name].wsgi --log-file -

runtime.txt

python-3.6.6

requirements.txt

django
gunicorn
django-heroku
numpy
scikit-learn
gensim

.gitignore

staticfiles
db.sqlite3
.spyproject/*

deploy

git init

heroku login
heroku create

git status
git add
git commit -m 'comments'

git push heroku master

heroku ps:scale web=1
heroku open

heroku ps:scale web=0
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2