Deploy Your Django App with Ease: A Step-by-Step Guide with Render

OnlyGod Ovbije
Django Unleashed
Published in
4 min readMay 15, 2023

--

Photo by Clément Hélardot on Unsplash

if you have developed a Django web application and you want to deploy it to the Render platform, then you are in the right place.

Render is a cloud platform that provides easy and fast deployment of web applications. In this blog, I will guide you through the steps to deploy your Django application to Render.

Let’s get started!!! 🚀🚀

Tools

Step 1: Create a Render account

First, you need to create a Render account by going to https://render.com/ and signing up. Once you have signed up, you need to create a new web service.

Step 2: Create a new web service

Click on the “Create a New Web Service” button on the Render dashboard. Then select “Web Service” from the dropdown menu. Next, you need to choose the Git repository where your Django application is located. If your repository is not public, you will need to provide Render with access to it.

Step 3: Configure the web service

After selecting your repository, you need to configure the web service. In the Runtime field, you need to select the language as “Python”.

Create a new web service
Creating web service

For the “Build command”, you will need to add a new file called build.sh on the home directory of your repo, to enable render to run more than one command on setting up your project, this script file will run on the deployment of the web service

add a file build.sh to main directory

build.sh



#!/usr/bin/env bash
# exit on error
set -o errexit

pip install -r requirements.txt

python manage.py collectstatic --no-input
python manage.py migrate

Now, In the “Start Command” section, you need to enter the command to start your Django application. For example:

gunicorn yourdjangoproject.wsgi:application

Make sure to replace “yourdjangoproject” with the name of your Django project.

Step 4: Add environment variables

If your Django application requires environment variables, you need to add them in the “Environment Variables” section. Click on the “Add Environment Variable” button and enter the name and value of the variable.

Also, ensure to add a PYTHON_VERSION by default, Render uses the latest patch version of Python 3.7.

add your env variables

Step 5: Configure the database

Also, if your Django application requires a database, you can configure it in the “Databases” section. Render supports several databases, including Postgres, MySQL, and MongoDB. Select the database you want to use and follow the instructions to configure it.

Create your database service
Copy database URL

Now, head over to info and copy your Internal Database URL and add it to your env variables, also first update your Django project settings file to fetch the DATABASE_URL.

import os

if not DEBUG:
DATABASES = {'default': dj_database_url.parse(os.environ.get('DATABASE_URL'))}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}}

Then update your env variables on the web service.

Update the Web service env

Step 6: Deploy the web service

Once you have saved your changes on the ENV variables, it automatically redeploys your application, you can head over to the Events tab on the web service and check the deployment status as shown below

Checking deployment status

Step 7: Access your Django application

After the deployment is complete, you can access your Django application by clicking on the “Open App” button. Render will provide you with a URL where you can access your application.

Congratulations!🚀🚀 You have successfully deployed your Django application.

Thanks for your time ♥

Where to find Me 👇

Here on Medium ♥️

You can also find me also 👉 Github https://github.com/Onlynfk/
Instagram / LinkedIn

Want to Work with me?

If you’re looking for a skilled developer to collaborate with, you can view my portfolio here. Let’s bring your ideas to life together

--

--