Subscribe to our YouTube Channel!
[Jul 12, 2021] New Video: How to Use Django Rest Framework Permissions (DRF Tutorial - Part 7)

Starting a New Django 1.8 Project

Starting a New Django 1.8 Project (Picture:

In this article you will find some useful tips regarding starting a new Django project and preparing a development environment. The steps below describes what I generally do when I’m starting a new project.

Step 1: Python Virtual Environment

If you have to maintain more than one Django project, at some point you will end up having problems with its dependencies, or with the Django version itself. The solution is to use virtualenv, which is a tool to create isolated Python environments.

It’s great because each of your Django project can live inside its own Python environment.

If you don’t have it yet, you can install it using pip:

$ pip install virtualenv

The basic usage of virtualenv would be, inside the folder you want to place your project, execute the following command:

$ virtualenv simple_django_skeleton

The instruction above will create a Python environment named simple_django_skeleton. In the end of the day, it’s just a folder with a Python installation inside. We will place our Django project folder and all its dependencies inside this folder.

Now, inside the simple_django_skeleton folder, activate the environment:

$ source bin/activate

You will notice that the name of the active virtualenv will now appear on the left of the prompt. Your terminal should look like something like this:


Step 2: Git Remote Repository

Using a version control system is a clever idea, even if you are gonna be working alone. I use Git as the version control system for the projects I develop, and GitHub as the remote storage.

I prefer to create the remote repository first on GitHub, and then clone it into my development environment. It’s cleaner this way.

Inside the simple_django_skeleton folder, clone your recently created repository:

git clone

Your folder structure should look like this:


Step 3: Install Django

With your virtualenv activated, install Django using pip:

pip install django

Step 4: Initialize the Project

Inside the simple-django-skeleton folder, which is the git repository, initialize the Django project:

django-admin startproject simple_skeleton .

Notice the dot in the end of the startproject command. It will start the project in the current folder.


Step 5: Install python-decouple, Unipath and dj-database-url

I use those three packages on all my Django projects. Python Decouple is a package to separe configuration variables from the source code (in case you missed our last week article about Python Decouple, you can read it here). Unipath will help you writing relative paths. Finally, dj-database-url will give you a cleaner way to write your database url.

pip install python-decouple
pip install Unipath
pip install dj-database-url

Step 6: Create a requirements.txt file

It’s important to keep track of your project’s requirements. Specially if you are gonna make it available for the public:

pip freeze > requirements.txt

Step 7: Add basic settings

First, remove the os import and the BASE_DIR definition and add the following imports:

from decouple import config
from unipath import Path
import dj_database_url

Define the PROJECT_DIR:

PROJECT_DIR = Path(__file__).parent

Define the static and media stuff, so Django won’t have problems finding your css/js files:

STATIC_ROOT = PROJECT_DIR.parent.parent.child('static')
STATIC_URL = '/static/'


MEDIA_ROOT = PROJECT_DIR.parent.parent.child('media')
MEDIA_URL = '/media/'

Define template folder, so Django will render your templates correctly:

        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [ PROJECT_DIR.child('templates') ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [

Decouple your settings params so you don’t commit any sensitive data or environment-specific param:

DEBUG = config('DEBUG', default=False, cast=bool)
    'default': dj_database_url.config(
        default = config('DATABASE_URL')

Create a .env file in the project root:


Make a copy of your .env file, name it .env.example and add some sample data. This will help people who will run your project later on, as we will make Git ignore the .env file:


Step 8: Create static and template folders

I like to create a folder to place project-wide templates (e.g. base.html) and static files inside the project folder:


To get things started I usually create a simple base.html template:

{% load static %}<!doctype html>
  <meta charset="utf-8">
  <title>{% block title %}Simple Skeleton{% endblock %}</title>
  <link rel="icon" type="image/png" href="{% static 'img/favicon.png' %}">
  <link href="{% static 'css/app.css' %}" rel="stylesheet">
  {% block content %}
  {% endblock %}
  <script src="{% static 'js/app.js' %}"></script>

Step 9: Create a .gitignore file

I use the GitHub’s Python .gitignore. Then I update it with the following:


The .DS_Store is a OSX file that’s automatically created by the OSX file explorer, Finder.

Step 10: Do a initial commit

Now we have a basic setup, we can commit our starting point:

git add .
git commit -m "Initial commit"

Step 11: Migrate

Migrate the Django models, in case you will be using django.contrib.auth, django.contrib.contenttypes etc:

python migrate

Step 12: Create first App

If the project’s model is not clear for me in the beginning, I usually create an app called core. If it starts to grow, I refactor the app.

One thing to keep your apps well organized, is to create a folder called apps, then you place all your Django Apps inside it. Also, I like to create my Apps inside the project folder, so it stays in the project’s namespace.

cd simple_skeleton
mkdir apps && cd apps
django-admin startapp core

The is required to properly import the apps.





Edit your project’s

from django.conf.urls import include, url
from django.contrib import admin

from simple_skeleton.apps.core import views as core_views

urlpatterns = [
    url(r'^$', core_views.home, name='home'),
    url(r'^admin/', include(,

Create a template folder inside the app core, and then inside create a folder named core and a file for our homepage home.html:

{% extends 'base.html' %}

{% block content %}
  <h1>Hello, World</h1>
{% endblock %}

Edit the app core adding our first view:

from django.shortcuts import render

def home(request):
    return render(request, 'core/home.html')

That’s it! As soon as I reach this point and got everything working fine, I start the development.

If you want to see the source code of this sample project, you can grab the source code on GitHub simple-django-skeleton.