Deploying Django Applications
1-100k daily requests
100k-1 million daily requests
1-100 million daily requests
1 billion daily requests
Is there a viable alternative to having to learn all this?
đđģ | âšī¸ | |
---|---|---|
setup: | requires little expertise | lack fine-grained control of infrastructure |
support: | ongoing maintenance is handled for you | |
cost: | can be quite expensive |
Tier | Cost | What you get |
---|---|---|
Hobby | $7/month | SSL |
Standard | $25-50/month | More RAM |
heroku login
Procfile
in the root of your Github repositoryProcfile
(no file extension)
release: python manage.py migrate
web: gunicorn cheeseshop.wsgi --log-file -
requirements.txt
:
Django~=4.0
# Easily configure a DB in Heroku:
dj-database-url~=0.5
# Webserver for WSGI apps
gunicorn~=20.1
# Database driver for PostgreSQL
psycopg2~=2.9
runtime.txt
to project root, specifying Python version to use:
python-3.10.4
settings.py
file a bit. (more soon...)SECRET_KEY
for your app:You can do this on the command-line with the heroku
app:
heroku config:set SECRET_KEY="9&%l8tqlhr4ibpq86#gcq_wxtr8272fd"
Any settings that you don't want to store in version control (like passwords) or that you want to vary by environment can be specified this way
You can also set these through the Heroku website
Heroku uses Git to get your app from your local machine up to Heroku's servers.
$> heroku git:remote -a cmsc-210-cheeseshop
$> git push heroku main
About that settings.py file...
$> heroku run python manage.py createsuperuser
Useful for creating an admin user in our database so we can sign in.
$> heroku logs
$> heroku addons
Add-on Plan Price State
âââââââââââââââââââââââââââââââââââââââââââââââ âââââââââ âââââ âââââââ
heroku-postgresql (postgresql-corrugated-17723) hobby-dev free created
ââ as DATABASE
$> heroku config
=== cmsc-210-cheese-shop Config Vars
DATABASE_URL: postgres://**********:b4c39d26b9f48a5b989c7efe46bb677f7cc7b1a50affab89b5c26529d7c87602@ec2-3-216-89-250.compute-1.amazonaws.com:5432/d94mllmcnmq0lu
SECRET_KEY: 9&%l8tqlhr4ibpq86#gcq_wxtr8572fdHJI
You can also try running:
$> heroku pg
What do we know so far?
Now we need to adjust our settings to use this database.