第一次使用后,Django Heroku推送失败并出现Grep使用错误

时间:2017-08-26 02:35:25

标签: python django git heroku

我有一个简单的Django应用程序,我正在尝试部署到Heroku。

我已按照将您的应用程序部署到Heroku 部分中列出的步骤进行操作:https://devcenter.heroku.com/articles/deploying-python

我正在离开分支heroku

当我执行git push heroku heroku:master时,第一次能够推送,一切都成功并且部署了应用程序,但是当我转到应用程序主页时,我收到503错误,表明favicon.ico不见了。然后我做任何小改动的提交,并再次尝试推送,我得到以下错误:

Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 360 bytes | 0 bytes/s, done.
Total 4 (delta 3), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing requirements with pip
remote:        Usage: grep [OPTION]... PATTERN [FILE]...
remote:        Try 'grep --help' for more information.
remote:
remote: -----> $ python manage.py collectstatic --noinput
remote:        Traceback (most recent call last):
remote:          File "manage.py", line 22, in <module>
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 337, in execute
remote:            django.setup()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
remote:            apps.populate(settings.INSTALLED_APPS)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
remote:            app_config.import_models()
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
remote:            self.models_module = import_module(models_module_name)
remote:          File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
remote:            __import__(name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
remote:            from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
remote:            class AbstractBaseUser(models.Model):
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
remote:            new_class.add_to_class('_meta', Options(meta, app_label))
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.py", line 331, in add_to_class
remote:            value.contribute_to_class(cls, name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
remote:            self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
remote:            return getattr(connections[DEFAULT_DB_ALIAS], item)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
remote:            backend = load_backend(db['ENGINE'])
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
remote:            return import_module('%s.base' % backend_name)
remote:          File "/app/.heroku/python/lib/python2.7/importlib/__init__.py", line 37, in import_module
remote:            __import__(name)
remote:          File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
remote:            raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
remote:        django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
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:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy....
remote:
remote: !   Push rejected to stark-fortress-79930.

我尝试过的事情:

  • 删除并重新创建应用程序,仍然每秒推送一次
  • 运行heroku run bash,并手动运行命令,同样的错误
  • psycopg2添加到我的requirements.txt
  • settings.py中修改和删除部分静态文件块,这是我目前所拥有的:

    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    STATIC_URL = '/static/'
    
    # Extra places for collectstatic to find static files.
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )
    

favicon.ico内有BASE_DIR/static

这是我的requirements.txt

beautifulsoup4==4.6.0
Cheetah==2.4.4
coverage==4.4.1
dj-database-url==0.4.2
Django==1.11.3
django-app-namespace-template-loader==0.4.1
django-blog-zinnia==0.18.1
django-contrib-comments==1.8.0
django-mptt==0.8.7
django-tagging==0.4.5
django-xmlrpc==0.1.7
gunicorn==19.7.1
mercurial==4.2.2
mots-vides==2015.5.11
olefile==0.44
Pillow==4.2.1
psycopg2==2.7.3
pyparsing==2.2.0
pytz==2017.2
PyYAML==3.11
regex==2017.7.11
six==1.10.0
virtualenv==14.0.6
whitenoise==3.3.0
zinnia-theme-bootstrap==0.5.1

任何人都能够了解我做错了什么?

1 个答案:

答案 0 :(得分:0)

您的问题是错误输出中的这一行:

+=

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2 添加到psycopg2。您的设置的其他一部分是设置Postgres数据库,您必须安装数据库驱动程序包才能使用。