Heroku has become a popular choice for developers looking to deploy web applications quickly and easily. If you’re a Django developer seeking a cost-effective hosting solution, you’re in luck! In this blog post, we’ll take you through a detailed step-by-step process of hosting your Django Python website for free on Heroku.
ATTENTION!!!
Heroku will no longer offer a free tier
Starting November 28, 2022, Heroku will stop providing a free tier to its users. The company announced this information on August 25, 2022, in this blog post.
READ OUR BLOG on How to Host/Deploy Django Python Website for FREE on Pythonanywhere
PLEASE GO THRU ABOVE BLOG. This is Completely Free and Can deploy your Django Website in just 5 Minutes
Deploy Django Website on Heroku
Step 1: Sign Up and Install Heroku CLI
- Create an account on Heroku (www.heroku.com).
- Install Heroku Command Line Interface (CLI) on your local machine.
Step 2: Set Up Your Django Project
- Make sure your Django project is version-controlled with Git.
- Ensure your project works locally and that the
requirements.txt
andProcfile
are correctly configured.
Step 3: Prepare Your Project
- Install Gunicorn (a production-ready WSGI HTTP server) using:
pip install gunicorn
- Create a
Procfile
(without any file extension) in your project’s root directory and add:
web: gunicorn your_project_name.wsgi
Step 4: Database Configuration
- If you’re using a database, make sure to configure it to work with Heroku. You might consider using Heroku’s PostgreSQL add-on.
Step 5: Commit Changes and Push to Heroku
- In your terminal, navigate to your project’s directory.
- Run the following commands:
git add .
git commit -m "Preparing for Heroku deployment"
heroku login
- Log in to your Heroku account using the browser that pops up.
- After logging in, create a new Heroku app:
heroku create <your-app-name>
Step 6: Deploy Your App
- Push your code to Heroku’s remote:
git push heroku master
- Heroku will automatically build and deploy your app.
Step 7: Run Migrations
- Run the initial migrations on the Heroku server:
heroku run python manage.py migrate
Step 8: Open Your Deployed App
- Once the migration is complete, you can open your app using:
heroku open
Step 9: Access Logs and Debugging
- To view logs, use:
heroku logs --tail
- If any issues arise, these logs will provide helpful information for debugging.
Conclusion
By following these steps, you’ve successfully deployed your Django Python website for free on Heroku. Its simplicity and seamless integration with Django make Heroku a fantastic choice for developers wanting to get their projects up and running quickly without the complexity of traditional hosting solutions. Start showcasing your Django apps to the world with Heroku’s hassle-free deployment process.