Deploying a Django Application to Heroku
You’re just a developer who writes code for a small project and hides it from the public. Instead of letting the world to know about what you are working on. If you answered yes to this, you are missing out something big. Not just one thing, but a lot. You’re missing stuff such as job offers, the next big startup. When you look at Facebook, if Mark chose not to deploy his first version of Facebook, today he wouldn’t be called a billionaire. Well, this post is not about becoming a billionaire but how to deploy a Django app on Heroku.
A friend of mine on LinkedIn approached me and asked how he can deploy a Django app. The best cloud platform you can deploy apps for learning purposes. So when he said that I knew he wanted a free tier and something easy to do. Well, Heroku does just that. You can host your apps on Heroku for free when you select hobby package.
I assume you already have a Django application running on your local server. You want some potential employers to see it live, follow along and get the help you need. Deploying an app on Heroku is not difficult at all, it’s pretty easy and you will agree with me soon.
In the root directory of your app create a file name Procfile with no file extension and add this line in the file
web: gunicorn yourName.wsgi — log-file -
All Heroku apps include a Procfile that specifies the commands that are executed by the app on startup, this is the place where you can write some instruction for your such as your apps webserver in our case we are using gunicorn
What next? You are almost done, now go to Heroku and create an account go for a hobby account it’s free with some cool add-ons the dashboard is easy to understand and though you can create an app from there we will use Heroku CLI to create the apps and push it.
Let’s create and push the app to the cloud now before that install Heroku CLI on your machine all instructions are in the link. Run the following commands in the terminal.
git add .
git commit -m "Procfile added"
heroku login #Login with your heroku acc credentials
heroku create your_app_name
git push heroku master
That is it! this should publish the app on Heroku and access it at https://your-app-name.herokuapp.com now you can pick it up from here and change the domain name to your custom name.
So Heroku is a nice cloud infrastructure where you can host your apps and the whole process is easy and I am sure you have agreed with me. In the next article, we will look at how to add persisting static files such as images on Heroku using Cloudinary.