2017-02-07 247 views
0

我的Python版本3.5.2是Django部署在Heroku

Django的版本是1.8.13

我做了一個Django應用程序,並想dploy到的Heroku。

當我輸入heroku open

然後本地服務器顯示應用程序錯誤。

谷歌搜索後。

我修復了我的wsgi.py,但仍然錯誤。

.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. 
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. 

"'DJANGO_SETTINGS_MODULE' environment variable must be set 

"django.core.exceptions.ImproperlyConfigured: 'DJANGO_SETTINGS_MODULE' environment variable must be set before importing 'whitenoise.django' 

File "/app/.heroku/python/lib/python3.5/site-packages/gunicorn/arbiter.py", line 506, in reap_workers raise HaltServer(reason, self.WORKER_BOOT_ERROR) 

gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3> 

wsgi.py

import os 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weather_station.settings") 

from django.core.wsgi import get_wsgi_application 

from whitenoise.django import DjangoWhiteNoise 

application = DjangoWhiteNoise(get_wsgi_application()) 

setting.py

local_setting.py

有什麼重要的概念我錯過了什麼?

[UPDATE]

procfile

web: gunicorn weather_station.wsgi --pythonpath weather_station

+0

請顯示您的Procfile。 –

回答

0

heroku config:set DJANGO_SETTINGS_MODULE=weather_station.settings

這是我用這種方式來設置的設置手動方式

0

這裏的settingsBASE_DIR位置是覆蓋由local_settingsBASE_DIR。所以,請嘗試將下方的行移至settings.py的頂部。

try: 
    from .local_settings import * 
except ImportError: 
    pass 

我建議你按照波紋管結構來處理本地和現場服務器的安靜設置。

settings/ 
    __init__.py 
    base.py 
    local.py 
    production.py 

wsgi.py添加兩個localproduction共同設置在base.py

而且local.py

import * from .base.py 
// Other settings required only for local server like 
// Example DEBUG = True 

production.py

import * from .base.py 
// Other settings required only for live server 
// Example DEBUG = False 

點製作設置。因此,改變

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings") 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project_name.settings.production" 

要啓動本地服務器點破本地設置,同時啓動本地服務器。

./manage.py runserver --settings=project_name.settings.local 

希望這有助於。