NinjaCipher:-*-:ro60

django alternate development settings file

So lately I’ve been working out all the kinks of running Django via pydev/eclipse so I can do more dev on my local machine. Since localy I run windows but I deploy onto Ubuntu Linux I’ve come up with a little hack that lets me conditionally load my project settings based on which environment it’s being run in. It’s pretty basic but I find it very helpful. If anyone else has any other approaches pls shout em out.

So all you have to do is create a file with all your development settings in your project folder (same folder the normal settings.py is in) and name it development_settings.py. Besides that you just have to replace the original manage.py in your project with the following manage.py. This one looks to see if your settings.py has DEBUG = True and if so loads the development.py instead.


#!/usr/bin/env python
from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.

    if settings.DEBUG:
        import development_settings
        startup_settings = development_settings
    else:
        startup_settings = settings

except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.nYou'll have to run django-admin.py, passing it your settings module.n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    execute_manager(startup_settings)
Del.icio.us Digg BlinkList Furl Ma.gnolia Reddit Spurl

Leave a Reply

You must be logged in to post a comment.