Set Different Settings for Development in Django

June 24th, 2010

djangoWhen you work in your local machine, most likely you need different settings. You can have this by adding a few lines of codes in your local settings.py. Put this code at the end of your settings.py

...
try:
    from settings_local import *
except ImportError:
    pass

and you create settings_local.py and overwrite some of the configurations and specify them according your local machine, don’t forget to set your version control (git, subversion, mercurial, etc) to ignore this file. For example while your production machine use mysql, you can use sqlite in your local machine:

settings.py

...
DATABASE_ENGINE = 'mysql' 
DATABASE_NAME = 'your-db-name'
DATABASE_USER = 'your-db-username'
DATABASE_PASSWORD = 'your-password'
...

settings_local.py

DATABASE_ENGINE = 'sqlite3' 
DATABASE_NAME = 'database.sqlite'

That’s it. Have fun.

Related posts:

  1. Relative Path for your Django Project
  2. Why We Need Version Control
  3. How to Install OSQA in Ubuntu Server
  4. Web Development Tools in Linux
  5. Django Tutorial – Simple Notes Application

4 Comments