Heroku - 无法导入设置(Django)

时间:2022-02-15 00:29:54

I've deleted the settings.py file and create a settings directory at the same level, And created three files. Here are these files.

我删除了settings.py文件并在同一级别创建了一个设置目录,并创建了三个文件。这些是这些文件。

  • settings/production.py
  • settings/staging.py
  • settings/__init__.py

and put in the init file the following statements.

并在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 *

But I am getting error raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)). Am I missing something? Thanks

但我得到错误引发ImportError(“无法导入设置'%s'(是否在sys.path上?):%s”%(self.SETTINGS_MODULE,e))。我错过了什么吗?谢谢

1 个解决方案

#1


1  

I've changed the Procfile and create a new common.py file in settings dir. Then I put the following contents in common.py. Now Both servers are running. Thanks :-)

我已经更改了Procfile并在设置目录中创建了一个新的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 File ->

Procfile文件 - >

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

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

#1


1  

I've changed the Procfile and create a new common.py file in settings dir. Then I put the following contents in common.py. Now Both servers are running. Thanks :-)

我已经更改了Procfile并在设置目录中创建了一个新的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 File ->

Procfile文件 - >

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

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