2013-04-22 2 views
1

settings.py 파일을 삭제하고 settings 디렉토리를 같은 수준에서 만들고 세 개의 파일을 만들었습니다. 여기에이 파일들이 있습니다. Heroku - 설정을 가져올 수 없습니다. (장고)

  • settings/__init__.pysettings/production.py
  • settings/staging.py
    • init 파일에 넣어 다음 문.

      site_env = get_env_variable('SITE_ENV') 
      if site_env: 
          if site_env == 'staging': 
           from .staging import * 
          elif site_env == 'production': 
           from .production import * 
      

      그러나 오류 raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))이 발생합니다. 내가 놓친 게 있니? 감사합니다

  • +0

    나는 모르겠지만에게 Heroku는'settings.py' 파일이 필요합니다. 해당 파일에서 조건을 확인하고 필요한 설정을 가져올 수 있습니다. – alix

    답변

    1

    나는 Procfile을 변경했으며 settings dir에 common.py 파일을 새로 작성했습니다. 그런 다음 common.py에 다음 내용을 입력합니다. 이제 두 서버가 모두 실행 중입니다. 감사합니다 :-)

    site_env = get_env_variable('SITE_ENV') 
    if site_env: 
        if site_env == 'staging': 
         from .staging import * 
        elif site_env == 'production': 
         from .production import * 
    

    Procfile 파일 ->

    web: python manage.py runserver --settings=myapp.settings.common 0.0.0.0:$PORT --noreload

    +0

    경고 : 위대한 큰 하나와 함께해야합니다. Heroku와 같은 프로덕션 환경에서'runserver' 명령을 개발 서버로 사용하지 마십시오. 그렇게하지 않으면 매우 불안정합니다. 대신 Heroku 문서에 따라 'gunicorn'또는 이와 동등한 것을 사용하십시오. –

    관련 문제