Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7982099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:34:34+00:00 2026-06-04T10:34:34+00:00

I have a small project that I want to deploy to both Heroku and

  • 0

I have a small project that I want to deploy to both Heroku and OpenShift, to try things out on both platforms. I’m using Python/Django So I want to take advantage of the dynamic import feature to define settings per environment, maintaining a settings module for those platforms I want to deploy to, like:

my_project/
    settings/
        __init__.py  <-- This is what's being imported during app init, here is where I want to detect which platform specific settings module to load
        dev_settings.py
        heroku_settings.py
        openshift_settings.py

So far I use this code:

ENVIRONMENT = the_function_or_code_that_returns_the_environment() # Defaults to "dev"
from django.utils.importlib import import_module

try:
    # Import any symbols that begin with A-Z. Append to lists any symbols that
    # begin with "EXTRA_".
    local_settings_module_name = '%s_settings' % ENVIRONMENT
    local_settings = import_module(local_settings_module_name)
    import re
    for attr in dir(local_settings):
        match = re.search('^EXTRA_(\w+)', attr)
        if match:
            name = match.group(1)
            value = getattr(local_settings, attr)
            try:
                globals()[name] += value
            except KeyError:
                globals()[name] = value
        elif re.search('^[A-Z]', attr):
            globals()[attr] = getattr(local_settings, attr)
except ImportError:
    pass

It would be prefered to detect this via default (not set by me/developer) environment variables. Heroku expose just a few:

DATABASE_URL
ENVIRONMENT
LANG
LD_LIBRARY_PATH
LIBRARY_PATH
PATH
PYTHONHASHSEED
PYTHONHOME
PYTHONPATH
PYTHONUNBUFFERED
SHARED_DATABASE_URL

And OpenShift’s:

OPENSHIFT_DB_HOST
OPENSHIFT_LOG_DIR
OPENSHIFT_TMP_DIR
OPENSHIFT_DB_CTL_SCRIPT
OPENSHIFT_REPO_DIR
OPENSHIFT_HOMEDIR
OPENSHIFT_GEAR_NAME
OPENSHIFT_PHPMYADMIN_IP
OPENSHIFT_RUNTIME_DIR
OPENSHIFT_INTERNAL_PORT
OPENSHIFT_PHPMYADMIN_CTL_SCRIPT
OPENSHIFT_DB_MYSQL_51_RESTORE
OPENSHIFT_DB_MYSQL_51_DUMP
OPENSHIFT_DB_PASSWORD
OPENSHIFT_DB_USERNAME
OPENSHIFT_PHPMYADMIN_GEAR_DIR
OPENSHIFT_RUN_DIR
OPENSHIFT_INTERNAL_IP
OPENSHIFT_GEAR_DIR
OPENSHIFT_GEAR_CTL_SCRIPT
OPENSHIFT_APP_DNS
OPENSHIFT_GEAR_TYPE
OPENSHIFT_GEAR_DNS
OPENSHIFT_DB_MYSQL_51_EMBEDDED_TYPE
OPENSHIFT_DB_URL
OPENSHIFT_APP_NAME
OPENSHIFT_DATA_DIR
OPENSHIFT_DB_SOCKET
OPENSHIFT_GEAR_UUID
OPENSHIFT_APP_UUID
OPENSHIFT_DB_TYPE
OPENSHIFT_DB_MYSQL_51_DUMP_CLEANUP
OPENSHIFT_DB_PORT

OpenShift variables are prefixed with OPENSHIFT_ so there’s a start, but that’s not the case with Heroku.

How can I reliably detect the platform using environment variables?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:34:36+00:00Added an answer on June 4, 2026 at 10:34 am

    @Kevin, I’m posting my comment it as an answer, so people can see it quickly (or improve it!):

    if len([k for k in os.environ.keys() if k.startswith('OPENSHIFT_')]):
        ENVIRONMENT = 'openshift'
    elif len([k for k in os.environ.values() if k.find('heroku') > -1]):
        ENVIRONMENT = 'heroku'
    
    local_settings_module_name = '%s_settings' % ENVIRONMENT
    local_settings = import_module(local_settings_module_name)
    # do the magic with the `local_settings` module
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small project that I was using node-dirty for, but it's not
I have a small project I am doing in Python using web.py. It's a
I have a small project that I will be working on shortly that collects
I have a small project and I noticed that I have a lot of
I have a small- to medium-size project that I am doing for my software
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I have a small Visual studio add-in that walks down active project and insert
I have done small project in c++, the IDE I am using is Visual
I have a small project I am working on which is WPF c# that
I have a small project that will have 1 user on 1 computer. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.