How To Deploy Django App To Heroku- The Simple Way
Have you ever tried uploading your django app to heroku but felt it was too complicated? If so, in this segment we will look at how you can upload your app to heroku. Don’t worry, it is going to be short and to the point.
For this tutorial, I will be assuming you have an app built, so the next step you will be delving into, is on how to deploy your app to heroku.
Keeping that in mind, let’s dive in and see how we can setup the app.
Prepare your app
Requirements.txt
If you are already working in a virtualenv
you can easily run to create your requirements.txt
file. https://gist.github.com/e9b170b07f5ad310b79beb52690c6963
Procfile
settings.py
https://gist.github.com/633fc00803165a92f7f92e9ee4fa9b19
and paste this at the bottom of the file or else you are going to get a KeyError
. https://gist.github.com/2bb602237854ef4303d4fc31a2c61d08
Django Static
This will basically tell django where to look for the static files and which folder to look for when collectstatic
is run.
We will need to create one more file called runtime.txt
. This will tell heroku which version of python needs to be installed. This step is optional because heroku will use a python version automatically when building but if you want a specific python version you can add it like this. https://gist.github.com/48222f0fcfd39f27c9492ff8fbc31547
That is it for configuring our app for deployment. Now we go to the heroku cli and see how to upload the app.
Deployment
If you don’t have heroku installed on your machine follow this link
After successful login we will be able to create our app directly from the terminal.
This will create a heroku app with a random available name. However, if you want to give a name of your choice, just add the name after heroku create
. Make sure the name is unique and available.
Once done this will deploy your app. Once deployed, we will need to migrate our database.
https://gist.github.com/2eb8994a8f9a7892980ed3b56c9eabd2
This will give us a quick terminal to control our app. Here you can run all your django commands.
https://gist.github.com/3649f1235e8287ff84feb03913094e7a
Conclusion
That is all for now. If you have followed all the steps above you should have an app which is now running on heroku. If you have come across any issues please leave a comment or knock-me. I will try to help fix them.
Best of luck. Happy coding :D
Originally published at http://github.com.