首页 文章

通过Git将Django项目部署到Heroku:“没有名为..的模块 - 失败”

提问于
浏览
0

我希望你能够帮助我,同时,我希望这个问题可以在将来很好地服务于其他人 .

基于Eric Matthes的优秀书籍:Python Crash Course,我正在尝试使用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"

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

pip freeze> requirements.txt

发布 - 手动添加它没有做到这一点 . 另外,我手动添加:

appdirs==1.4.3

接下来,我按照网站上的说明指示如何禁用收集静态:

heroku config:set DISABLE_COLLECTSTATIC=1

这种组合让我更进了一步 .

第3部分完成所有这些,我现在能够成功运行代码:

git push heroku master

但是,运行:

heroku ps

之后直接显示崩溃

web.1:crashed 2018/12/09 11:24:35 0100(~42m ago)

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

heroku运行python manage.py migrate

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

ModuleNotFoundError:没有名为'dj_database_url'的模块

看看我的requirements.txt文件,我在这里的列表中显然有这个 .

由于网络中的主要引用要么检查它是否包含在requirements.txt文件中,gunicorn文件是否正确定义或者collectstatic被禁用 - 我不知所措,我希望有人也可以帮助解决这个问题 . 希望,上述指针将有益于处理同样早期问题的其他人 .

我的文件如下:

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

    好吧,在经过多次测试后,我终于意识到需求文件一直在变化(我很确定,不仅仅是在我运行冻结时) .

    因此,以前安装的多个软件包不再位于requirements.txt文件中 . 从本质上讲,这意味着,这个错误实际上归结为requirements.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
    

相关问题