Heroku推送拒绝(Django应用程序)

时间:2016-04-21 09:28:28

标签: django heroku github

我正在向GitHub和Heroku部署Django应用程序 我首先将它部署到GitHub,删除(将它放在.gitignore文件中)“settings.py”,现在我正试图将它推送到Heroku,我收到一个错误:

ImportError: No module named settings
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

如何避免将某些文件推送到GitHub,但同时有可能将其推送到Heroku?

更新:

我试图将settings.py和temp_settings.py分开,但现在该应用程序不再有效了。当我尝试运行本地服务器时,这是追溯:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
    settings.INSTALLED_APPS
  File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
    self._setup(name)
  File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/stefano/projects/blog-project/blogprojectenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/stefano/projects/blog-project/blogproject/settings.py", line 104, in <module>
    DATABASES['default'].update(db_from_env)
NameError: name 'DATABASES' is not defined

看起来settings.py无法“到达”temp_settings.py,因为我已经在temp_settings中剪切粘贴了所有数据库设置。这是错的吗?

1 个答案:

答案 0 :(得分:0)

通常的做法是不要忽略代码库中的settings.py文件。相反,做一些像:

try:
    from temp_settings import *
except ImportError:
    pass

在settings.py文件的末尾,并将temp_settings.py添加到.gitignore

对于您需要保密的凭据,请使用temp_settings。