Django 如何检测工头是否在运行

Django 如何检测工头是否在运行,django,heroku,foreman,Django,Heroku,Foreman,我正在使用eclipse开发我的Django项目,它将被部署到Heroku。为了检测应用程序是否在Heroku上运行,修改了settings.py: if 'DYNO' in os.environ: # Is running on Heroku DEBUG = False else: DEBUG = True ... if DEBUG==True: DATABASES = { 'default': { ...

我正在使用eclipse开发我的Django项目,它将被部署到Heroku。为了检测应用程序是否在Heroku上运行,修改了
settings.py

if 'DYNO' in os.environ:    # Is running on Heroku
    DEBUG = False
else:
    DEBUG = True
...

if DEBUG==True:
    DATABASES = {
        'default': {
            ... 
        }
    }
else:    # For Heroku
    # Parse database configuration from $DATABASE_URL
    import dj_database_url
    DATABASES = {'default':dj_database_url.config()}
    # Honor the 'X-Forwarded-Proto' header for request.is_secure()
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
同时修改wsgi.py:

from <myApp> import settings

if settings.DEBUG==True:
    application = get_wsgi_application()
else:    # For Heroku
    from dj_static import Cling
    application = Cling(get_wsgi_application())
来自导入设置的

如果settings.DEBUG==True:
application=get\u wsgi\u application()
其他:#为Heroku
从dj_静态导入粘滞
application=Cling(get\u wsgi\u application())
上面的修改是为了确定应用程序是使用
runserver
本地运行还是在Heroku上运行。但是,如果我尝试运行
foreman start
而不是
runserver
,则
wsgi.py
中的设置将不起作用,因为
foreman
也需要
Cling


是否有一种方法可以检测应用程序是否由
工头运行,以便我进行正确设置?

Heroku为您提供
数据库URL
,因此如果“
数据库URL
”不存在,则它是本地机器

if not os.environ.has_key('DATABASE_URL'):
        os.environ['DATABASE_URL'] = 'postgres://user:password@localhost/name'

DATABASES = {'default': dj_database_url.config(default=os.environ['DATABASE_URL'])}
更新:匹配正确问题的答案

程序文件

wsgi.py


谢谢,但我不想确定该应用程序是在本地运行还是在Heroku上运行。我正在尝试确定应用程序是使用
manage.py runserver
本地运行,还是使用
foreman start
@yltang52进行本地运行。很抱歉,重播太晚了,我正在旅行。我更新了我的答案。
export SERVER_ENV=foreman
web: gunicorn yourapp.wsgi
if os.getenv('SERVER_ENV') == 'foreman':
    application = Cling(get_wsgi_application())
else:
    application = get_wsgi_application()