Heroku Commands for Django


So heroku is a service that offers a great way to deploy Django-powered websites.

In fact, the forum for this website, docpid, is a Django website that is deployed using heroku, and it works very well this way.

So in order to work with heroku in order to deploy a Django site, you must learn some of the most important commands for Django.

Heroku actually makes this very simple, because the Django commands are very similar to the Django commands that you would run on a local server you are running on your computer.

Below is a table that goes over many of the most important heroku commands when working with a Django website.

Command Purpose
heroku run python manage.py collecstatic Transfers all static files to the static server
heroku run python manage.py makemigrations Updates changes to database tables
heroku run python manage.py migrate Makes changes to database tables or apps available across the entire project

There really aren't many commands that are specific to Django that you would need outside of these 3 commands.

With the collecstatic function, you can transfer static files from your local static directory to the liver server directory, whether that be amazon web services, google cloud, or Microsoft Azure.

The next important commands are just making for making changes to the databases or if you've made any changes to any apps.

If you've made a change to a database, then you would run the heroku makemigrations command. This would update the changes in the live database that you've set up in your Django project.

Now in order to make all apps within your project know that this change has occurred to this database, you would run the heroku migrate command. You would also run this command if you've added or deleted any apps from the INSTALLED_APPS list in the settings folder.

These are some of the most important commands that you need to run a Django website with heroku.

Related Resources

How to Randomly Select From or Shuffle a List in Python

HTML Comment Box is loading comments...