Easy Technology Tips, Tricks & Guides

How to Clone and Run a Django Project Locally

Open-source projects are increasingly in demand, and there’s a huge number to sink your teeth into. To start working on an open-source project, it helps if you can easily clone the source code and set the project up locally.

Although cloning may seem easy, it can be challenging with projects built with Django. Django has many dependencies and packages that cause conflicts when not installed.

You must fix the conflicts before the project can run on your local machine. Well, you don’t have to suffer anymore.

In the next steps, you will learn how to clone, set up, and run your Django project with minimal conflicts.

What You Will Need

To get the most from this guide, you should have the following:

  • Python (Python3 and above)
  • A working knowledge of the Python-Django Library
  • Pip3
  • Familiarity with Python virtual environments
  • Basic knowledge of Git and GitHub
  • A GitHub account
  • Git installed on your local machine
  • Familiarity with the command line

With these requirements fulfilled, you’re ready to clone a project.

1. Clone the Project From GitHub

You can clone a sample project from GitHub and configure it on your local machine.

Image shows the Django project to be cloned on GitHub

To clone the project, click on the green button labeled Code. On the dropdown, select and copy either HTTP or SSH links. These links are the GitHub URLs for the project. Any of them will do.

Back to your machine, set up a folder named clone_boma. Remember to navigate into the folder with the cd clone_boma command.

Next, run the following command to clone the project into the folder.

git clone <repository-url>

So, to clone the sample project over HTTP, use this command:

git clone https:

2. Inspect the Project Files

After cloning, use the ls command to check the files from the Boma-watch project are present. Type ls to list all the content in the folder.

You can use a text editor of your choice to inspect the contents of each file or view them on the GitHub website.

3. Set Up a Virtual Environment

You need to set up a virtual environment for the project. The sample project comes with a Pipenv environment which specifies the project’s dependencies in two files: Pipfile and Pipfile.lock.

You will encounter this error if you run the project with the old Pipfile:

ModuleNotFoundError: No module named ‘distutils.core’

You need to delete the virtual environment and install it afresh. To delete the virtual environment and its dependencies, run the following commands consecutively.

To remove the old environment:


To remove both Pipfiles:

rm Pipfile* 

To install your Pipenv dependencies on your python version:

pipenv install 

Next, run the following command to install all Pipfiles packages:

pipenv install requests

Then activate the virtual environment:

pipenv shell

You will see the virtual environment activated on the right side of your terminal window.

If you are using Venv to create your virtual environment, run the following to install dependencies:

pip install -r requirements.txt

To list out all the installed dependencies:

pip freeze > requirements.txt

4. Create a Database

You need to install a database to handle the project data. You can choose any kind of database that suits your needs. For the sample project, you should use PostgresSQL.

Learn how to install PostgreSQL on Ubuntu or install PostgreSQL on Windows.

Once all is set, start the Postgres shell using the following commands:

sudo -i -u postgres

Then create a database named new_boma on the server:


The server returns the word CREATE DATABASE when it creates a database. Confirm that the database exists by listing all databases in the system with the command \l:

Image shows newly created database in system

In, you need to connect the database to the application. Do this by replacing the database user, name, and password with your own local values:

'default': {

Also, remember to change TIME_ZONE in the file to suit your location. This will keep your app updated.

Ensure you have installed Psycopg2 to accommodate any images available:

$ pipenv install psycopg2

5. Generate a Secret Key

Every Django project has a unique secret key. Usually, the secret key is not exposed online. It should be in an env file which you should include in a .gitignore file to exclude from the repository.

You have to generate a new one for your project to run. Create a new secret key with a secret key generator, like Djecrety.

SECRET_KEY = 'secret-key-comes-here'

6. Migrate Project to the Database

Run the following command to create tables for the app in the new database:

python makemigrations app

Then run the following to migrate:

python migrate

When you run the python migrate command, you experience errors. The errors are notifying you of missing modules. Make sure to install all modules before you migrate.

When you have all the dependencies installed, run the migration. If the migrations finish, it’s time to run the project.

When you have all the dependencies installed, run the migration. If the migrations run, it’s time to run the project.

7. Run the Project

Run the project to ensure everything is okay before adding your contribution. Run the application with the following command:

python runserver

If there are no errors, open in a web browser. You will see the landing page of the project as shown below:

Image shows project landing page

The Secret to Cloning a Django Project

Cloning Django projects helps to optimize your time. You can concentrate on developing new features instead of starting a project from scratch.

The secret to cloning and running a Django project on a local machine is to know how to handle the dependencies. After cloning, ensure you create a new virtual environment, install dependencies, and connect to a reliable database system.

Django is a powerful Python library. Learn how to clone and use its projects to create amazing applications that impact the tech community.


>>Here is the Original Post!

Leave A Reply

Your email address will not be published.