通过Git将Django项目部署到Heroku:“未命名模块。-失败”

时间:2018-12-09 11:21:07

标签: python django heroku django-bootstrap3

我希望您能够为我提供帮助,同时,我希望这个查询将来可以在这里为其他人带来好处。

基于Eric Matthes的著作《 Python崩溃课程》,我试图使用Git将Django应用程序部署到Heroku,并遇到了一些问题。请注意,这本书有一些更正:https://ehmatthes.github.io/pcc/updates.html

我在这里特别提到这本书,因为我认为它是各个网站上最好的入门书籍之一,因此我可以想象其他人面临同样的问题-而且,与这3个相关的帖子很多主题。

最初,可以将应用提交到Git,但是不能使用以下命令推送到Heroku:

  

git push heroku master

第1部分: 不断产生错误:

No Procfile and no package.json file found in Current Directory - See heroku local --help

要解决此问题,至关重要的是确保文件没有扩展名(mac os)没有显示它,但是目录中的ls显示文件结尾的.txt。

第2部分: 重试此操作,现在允许发送新消息:

ModuleNotFoundError: no module named 'bootstrap3"

可以通过以下命令确保django-bootstrap3 == 6.x.x需求在requirements.txt文件中可用来解决:

  

点冻结> requirements.txt

已发布-手动添加并不能解决问题。 另外,我手动添加了:

appdirs==1.4.3

接下来,我按照网站上的说明进行操作,指示如何禁用“收集静态信息”:

heroku config:set DISABLE_COLLECTSTATIC=1

这种组合使我更进一步。

第3部分 完成所有这些之后,我现在可以成功运行代码:

  

git push heroku master

但是,正在运行:

  

heroku ps

此后直接显示崩溃

  

web.1:崩溃于2018/12/09 11:24:35 +0100(〜42m以前)

尝试使用以下命令迁移数据库:

  

heroku运行python manage.py migration

现在让我知道,它缺少以下模块:dj-database-url

  

ModuleNotFoundError:没有名为“ dj_database_url”的模块

不过,看看我的requirements.txt文件,我显然在这里的列表中。

由于网络中的主要参考是要检查它是否包含在requirements.txt文件中,所以正确定义了gunicorn文件或禁用了收集静态功能-我很茫然,希望有人可以提供帮助不仅如此,而且希望上述指针会对其他处理相同早期问题的人有所帮助。

我的文件如下:

Procfile

web: gunicorn learning_log.wsgi —-log-file -

Procfile用大写字母“ P”表示,该应用程序称为learning_log

requirements.txt

astroid==2.1.0
autopep8==1.4.3
dj-database-url==0.5.0
dj-static==0.0.6
Django==2.1.3
gunicorn==19.9.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pycodestyle==2.4.0
pylint==2.2.2
pytz==2018.7
six==1.11.0
static3==0.7.0
wrapt==1.10.11
django-bootstrap3==6.2.2
psycopg2>=2.6.1
appdirs==1.4.3

wsgi.py

import os

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "learning_log.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)

settings.py文件中的片段:

# Settings for django-bootstrap3
BOOTSTRAP3 = {
    'include_jquery': True,
}

# Heroku Settings
cwd = os.getcwd()
print("--- CWD ---\n", cwd, "\n---\n")
if cwd == '/app' or cwd[:4] == '/tmp':
    import dj_database_url
    DATABASES = {
        'default': dj_database_url.config(default='postgres://localhost')
    }

    # Honor the 'X-Forwarded-Proto' header for request.is_secure().
    SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

    # Allow all host headers.
    ALLOWED_HOSTS = ['*']

    # Static asset configuration
    BASE_DIR = os.path.dirname(os.path.abspath(__file__))
    STATIC_ROOT = 'staticfiles'
    STATICFILES_DIRS = (
        os.path.join(BASE_DIR, 'static'),
    )

    STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

runtime.txt

  

python-3.7.0

我衷心希望,有人可以在这里提供帮助-我对可能还需要什么感到茫然。

我希望这足以解释-我知道显然Heroku方面也有一些更新,但是要了解这一点确实很困难。

非常感谢, 西蒙

1 个答案:

答案 0 :(得分:0)

好吧,经过大量的测试-我终于意识到需求文件不断变化(我很确定,不仅是在冻结时)。

因此,以前安装的几个软件包不再位于requirements.txt文件中。本质上,这意味着该错误实际上归因于beesing.txt文件完整且包含所有必需的软件包。

我的最终包裹清单如下:

appdirs==1.4.3
astroid==2.0.4
certifi==2018.8.24
chardet==3.0.4
cycler==0.10.0
Django==2.1.1
django-bootstrap3==11.0.0
dj-database-url==0.5.0
dj-static==0.0.6
gunicorn==19.3.0
idna==2.7
isort==4.3.4
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
matplotlib==2.2.2
mccabe==0.6.1
numpy==1.15.0
psycopg2>=2.6.1
pygal==2.4.0
pygal-maps-world==1.0.2
pygame==1.9.4
pylint==2.1.1
pyparsing==2.2.0
python-dateutil==2.7.3
pytz==2018.5
requests==2.19.1
six==1.11.0
static3==0.6.1
urllib3==1.23
virtualenv==16.0.0
whitenoise==4.1.2
wrapt==1.10.11
相关问题