在django上设置多个环境的正确方法是什么?

时间:2016-05-24 17:27:31

标签: python django heroku development-environment production-environment

我按照教程为我的django应用程序提供了生产和本地环境。但当我把它推到heroku时,它被拒绝了。虽然它在当地运作良好。我创建了一个名为settings的文件夹,并通过放置__init__.py insde使其成为一个模块。我更改了原始settings.py的名称,并将其命名为Old_settings .py。然后我创建了一个名为base.py的文件,其中包含我原来的settings.py代码。然后在init文件中我做了这个

from .base import *

try:
    from .local import *
except:
    pass

try:
    from .production import *
except:
    pass

在制作中

import os
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = False

在当地

import os
import dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
SECRET_KEY = '------------------------------------------'
DEBUG = True

我也改变了这个

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

到这个

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))

但是当我把它推到heroku大师时,它被拒绝了。我缺少什么

编辑我的完整错误消息

        Counting objects: 18, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (17/17), done.
    Writing objects: 100% (18/18), 3.10 KiB | 0 bytes/s, done.
    Total 18 (delta 11), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    remote: -----> Using set buildpack heroku/python
    remote: -----> Python app detected
    remote:      $ pip install -r requirements.txt
    remote: 
    remote:      $ python manage.py collectstatic --noinput
    remote:        Traceback (most recent call last):
    remote:          File "manage.py", line 10, in <module>
    remote:            execute_from_command_line(sys.argv)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    remote:            utility.execute()
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    remote:            self.execute(*args, **cmd_options)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    remote:            output = self.handle(*args, **options)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    remote:            collected = self.collect()
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
    remote:            for path, storage in finder.list(self.ignore_patterns):
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
    remote:            for path in utils.get_files(storage, ignore_patterns):
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    remote:            directories, files = storage.listdir(location)
    remote:          File "/app/.heroku/python/lib/python3.5/site-packages/django/core/files/storage.py", line 299, in listdir
    remote:            for entry in os.listdir(path):
    remote:        FileNotFoundError: [Errno 2] No such file or directory: '/app/gettingstarted/settings/static'
    remote: 
    remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
    remote:        See traceback above for details.
    remote: 
    remote:        You may need to update application code to resolve this error.
    remote:        Or, you can disable collectstatic for this application:
    remote: 
    remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
    remote: 
    remote:        https://devcenter.heroku.com/articles/django-assets
    remote: 
    remote:  !     Push rejected, failed to compile Python app
    remote: 
    remote: Verifying deploy...
    remote: 
    remote: !       Push rejected to examplesite.

remote: 
To https://git.heroku.com/examplesite.git
 ! [remote rejected] master -> master (pre-receive hook declined)

我的老路是

 src/gettingstarted/settings.py 

但现在是

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

我认为这是一个目录问题但我对如何纠正它感到有点困惑

0 个答案:

没有答案
相关问题