q5nepa
Last Updated: February 25, 2016
·
7.855K
· iepathos
0163b9f584a32057bdb8d31ee43891e0

How to setup local_settings.py for your Django 1.4.2 project

Get your Django project setup for your local development environment - Quick and Clean

Written by Glen Baker - iepathos@gmail.com <a href="http://coderwall.com/iepathos"></a>
See project files on https://github.com/iepathos/djsetuplocal

I learned this method from django-workshop.de

Start a new Django 1.4.2 project - djsetuplocal

django-admin.py startproject djsetuplocal
cd djsetuplocal/djsetuplocal

Edit settings.py

djsetuplocal/djsetuplocal/settings.py

import os
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))

DEBUG = False
# delete TEMPLATE_DEBUG = DEBUG

At the bottom of settings.py, below Logging

try:
  from local_settings import *
except ImportError:
  pass

Enter all local information in local_settings.py

djsetuplocal/djsetuplocal/local_settings.py

# Grabs the site root setup in settings.py
import os
from settings import SITE_ROOT

DEBUG = True
TEMPLATE_DEBUG = DEBUG

# sqlite is the quick an easy development db
DATABASES = {
  'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': os.path.join(SITE_ROOT, 'djlocal.db'),
      'USER': '',             # Not used with sqlite3.
      'PASSWORD': '',         # Not used with sqlite3.
      'HOST': '',             # Not used with sqlite3.
      'PORT': '',             # Not used with sqlite3.
  }
}

And you're good to go.

To make sure localsettings works well with Git Version Control make sure to add localsettings to .gitignore

djsetuplocal/.gitignore

*.pyc
*.pyo
.installed.cfg
bin
develop-eggs
dist
downloads
eggs
parts
src/*.egg-info
lib
lib64
local_settings.py
*~
Say Thanks
Respond
Filed Under