🐍 Build Your First Django Website: Day 10

You’ve built something amazing—now it’s time to share it with the world! Today, we’ll walk through deploying your Django website so anyone, anywhere can access it.

Take your learning to the next level with quick, aesthetic coding tutorials on my YouTube channel! 🚀✨

🎥 Watch now: @CtrlCPython

Subscribe for bite-sized Python lessons with lofi vibes & clean code. ☕🎶 

Day 10: Deploy Your Django Website

Now let’s deploy your website to the web!

1. Choose a Hosting Service

There are several hosting services for Django. A popular choice is Heroku because it's free for small projects, easy to use, and scales well.

2. Set Up Heroku

Follow the Heroku Django deployment guide to deploy your site or see the next steps below:

a. Install the Heroku CLI

Follow the instructions to install the command line interface.

b. Verify your installation

heroku --version

c. Log in to Heroku

Create an account on the Heroku website and log in via the command line.

heroku login

d. Install required packages

Your Django app needs specific dependencies to run on Heroku. Install them using:

pip install gunicorn django-heroku
pip freeze > requirements.txt

e. Update mysite/settings.py

Modify your mysite/settings.py to integrate Heroku's configurations:

f. Create a Procfile

Heroku needs a Procfile to know how to run your app. In your project's root folder, create a file named Procfile and add:

web: gunicorn mysite.wsgi

3. Push to Heroku

Now that everything is configures, let’s deploy the project!

a. Initialize a Git repository (if not already done)

git init
git add .
git commit -m "Initial commit"

b. Create a Heroku app

heroku create my-first-django-website

c. Push the code to Heroku

git push heroku main

d. Run database migrations

heroku run python manage.py migrate

e. Open your live site

heroku open

🏆 Final Thoughts

Congratulations! 🎉 You've now learned how to build, deploy, and manage a Django website.

Keep exploring Django’s powerful features, and soon you’ll be building advanced web applications!

If you missed out on the previous step, head on over to this post.

If you want to see an overview of all of the steps, check out this post.

Having trouble with this step? Let me know in the comments! 🚀🐍

Happy coding! 🚀🐍

Digital Shade

Want more Python tips and tricks?

🔔 Join my Beehiiv newsletter for exclusive cheat sheets, Python hacks, and expert tutorials!

Reply

or to participate.