Heroku is a cloud application platform, it facilitate the deployement of a web application.
They support several programming languages, include Python.
To install heroku Toolket Sign up to heroku,
Then install the Heroku Toolbet it is very powerful command line tool it will help you to manage your application.
After installing the Toolbet, open your Terminal/CMD and login to your account :
$ heroku login Enter your Heroku credentials. Email: your email Password (typing will be hidden): Authentication successful.
place into your application
$ cd my-application/
Here is the list of things you will probably need to add to your project:
- Add a Procfile in the project root;
- Add requirements.txt file with all the requirements in the project root;
- Add Gunicorn to requirements.txt;
- A runtime.txt to specify the correct Python version in the project root;
- Configure whitenoise to serve static files.
- Create a file named Procfile in the project root
- Add the following content :
web: gunicorn my-application.wsgi --log-file -
Note: change my-applicatio with the name of your Django project.
Run this command, this command will list all dependencies :
$ pip freeze > requirements.txt You should see somthing like this : dj-database-url==version Django==version gunicorn==version psycopg2==version psycopg2-binary==version pytz==version whitenoise==version
Create a file named runtime.txt in the project root, and put the specific Python version your project use:
Configure the STATIC-related parameters on settings.py:
$ pip install whitenoise
Add the Whitenoise to your Django application in the wsgi.py file:
""" WSGI config for repertoire project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ """ import os from whitenoise.django import DjangoWhiteNoise from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my-application.settings') application = get_wsgi_application() application = DjangoWhiteNoise(application)
Update the settings.py
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Add whitenoise middleware at the top of the middleware list in settings.py
import dj_database_url prod_db = dj_database_url.config(conn_max_age=500) DATABASES['default'].update(prod_db)
$ heroku create myapplication Creating ⬢ myapplication... done https://myapplication.herokuapp.com/ | https://git.heroku.com/myapplication.git
Choose any name for your app. Heroku will inform you if the name already exists
ALLOWED_HOSTS = ['myapplication.herokuapp.com']
Initialize Git and connect your new app (or existing one) to Heroku Git remote repository and push the application.
in your terminal / CMD :
$ git init $ heroku git:remote -a myapplication $ git add . $ commit -m "Initial commit" $ git push heroku master
If you get an error message with collectstatic, simply disable it by instructing Heroku to ignore running the manage.py collecstatic command during the deployment process.
$ heroku config:set DISABLE_COLLECTSTATIC=1
Then, run :
$ git push heroku master
Migrate the database :
$ heroku run python manage.py migrate
Let me know in comment section if you've any error.
Thank you for reading.
The project we're building is going to be an application that will store/retrieve Event Logs. You could use this for something like tracking requests you're making, or tracking audit events in a log, or...well, anything that would require storing some arbitrary events with types, messages, and payloads.