SaralGyaan, Saral Gyaan, Saral Gyan is website which provides free tutorials of Python for absolute beginners in English and Hindi, Learn Python in Hindi, Learn Python for absolute beginners, Learn Python, bootstrap, django, git

Hari S
Author: Hari S

Best way to start a Django project (with Github Integration)

  • Aug. 6, 2019, 3:06 p.m.
  • 4 minutes read
  • 0 Comment
Best way to start a Django project  (with Github Integration)

There are dozens of ways, which developers use to start their Django projects. Possibly, none of them would be a wrong way, but in this post we will be telling you a way which is very helpful and suitable not only in development but also in production (deployment). Not only this, in this post we will teach you how to integrate Git/Github with your project from the very beginning.

Creating the Project Directory

So, let’s get to the work. First of all, I will suggest you to choose a location on your machine (Windows/ Mac), where you want to save most of your projects and cd to that directory. Then create a new directory and cd into that:

$ mkdir dev
$ cd dev

Now, this dev folder will host all of your individual projects. Inside this dev folder create a new directory (with the name of your project/app) and cd into that. This directory will be referred to as your project directory:-

$ mkdir newproject && cd newproject

Creating and activating the Virtual Environment

Install virtual environment and activate it.

$ virtualenv -p python3 .
# or
$ virtualenv .

# Activate on MACOS/Linux
$ source bin/activate

# Activate on Windows

Create a new directory with name ‘src’

$ mkdir src && cd src

Installing Django and starting the project

Use pip to install django

$ pip install django

Now inside the src directory create the project

$ startproject newproject .

You must note the following two things.

  1. We have started a project with name ‘newproject’ and same is the name of the project directory (and also the virtualenv).
  2. There is a trailing . (dot).

Creating local Git repository

Browse to the project folder (i.e. newproject) and run the following command. This will initialize an empty Git repository.

$ git init

Now create a file called .gitignore in the project directory. The function of this file is that, it will not add the folders\files mentioned (pattern) in it to the git repository. This is used for not adding venv, env, temp, db files to the repository.

You can download the standard .gitignore file from here.

Creating a remote Git repository on Github

Open github, log in to your account and create a new repository. Add the name (preferably project name) and description of the repository and create it.

Screenshot 2019-08-06 at 3.36.16 PM.png

You won’t like to share your important credentials on the github etc. For that we will be using Python Decouple.

$ pip install python-decouple

Create a .env file inside the directory where file is (i.e. src)

$ nano .env

Open the file and copy the SECRET_KEY from your


Add the following two lines in your

from decouple import config

Now go to the project directory and check git status to see the files that are untracked

$ git status

You will get something like this

On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)


Now, add the files and make initial commit using the following codes:-

$ git add .
$ git commit -m "Initial Commit"

If you will check git status now, it will show the following:

$ git status

On branch master
nothing to commit, working tree clean

Now add the remote origin using this :

git remote add origin

It will ask you for the username and password of the github account and then will push it to Github.

You can check the Github repository here

We also have a one minute video tutorial on our channel

Tags: Django

Related Posts

How to extend Django User model using a proxy model?
By Hari S | 2 weeks, 1 day ago
How to Extend Django User model using AbstractUser?
By Hari S | 2 weeks, 1 day ago


Be the first one to comment!