Check out my heroku delopyment here! cool count
Why Heroku?
Heroku is a good option for the fast setup and easy deployments since its environment configuration is fairly simple. It is initially free!
Firstly, start a virtual environment. Check this post to know more about virtual environment.
Activate the virtual environment with:
$ source venv/Scripts/activate
Create a “requirements.txt” and “static” folder as follow:
In settings.py, add the following lines:
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'staticfiles')
]
Install WhiteNoise:
$ pip install whitenoise
It allows your own hosted website to serve its own static files.
And add the following in setting.py:
MIDDLEWARE = [
# 'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]
Copy all the installed files:
$ pip freeze > requirements.txt
Create “Procfile” (no file type)
web: gunicorn cool_counters.wsgi --log-file -
Note: cool_counters is an app name
Copy all files from your static folders into the STATIC_ROOT directory:
python manage.py collectstatic
Push all the changes to Github and deploy it to heroku!
References
http://whitenoise.evans.io/en/stable/
https://docs.djangoproject.com/en/3.2/howto/static-files/