tags:

views:

49

answers:

3

In Rails, there's an environments variable called RAILS_ENV that tells you which environment you're in. Other than creating my own environment variable, is there a default one that tells you which environment you are in in Django?

+2  A: 

Django doesn't have quite the same concept of "environment" like Rails' "production", "development", and "test". The closest thing is the DEBUG variable (set your Django project's settings.py file), which should be True for development and False for production. Outside of settings.py, you can obtain it with:

from django.conf import settings
print settings.DEBUG
mipadi
+1  A: 

Often, many things change between "environments".

We have separate settings files for each environment.

Each environment-specific file starts with

from settings import *

To bring in the default settings for the application as a whole.

We have settings_dev, settings_checkout, settings_qa, settings_prod, etc.

S.Lott
+1  A: 

As mipadi said, there's no "official" variable like Rails has. There's nothing to stop you from creating your own though. You could use the method S. Lott suggested to separate your settings out into separate files and inside each one have a line like:

DJANGO_ENV = 'Production'

Then you could easily access it anywhere:

from django.conf import settings
if settings.DJANGO_ENV == 'Production':
    print "I'm in production!"
Steve Losh