我希望你能帮助我,同时,我希望这个问题可以在未来为这里的其他人服务。
基于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"
这可以通过确保Django-BooTrrAP3==6 .x.x要求在命令时可以在Realths.txt文件中得到解决:
PIP冻结>requirements.txt
发布-手动添加它没有办法。
此外,我还手动添加了:
appdirs==1.4.3
接下来,我按照一个网站上的说明操作,该网站指导如何禁用collect static:
heroku config:set DISABLE_COLLECTSTATIC=1
这个组合让我更进一步。
第3部分
所有这些都完成了,我现在可以成功地运行代码:
吉特推英雄大师
但是,运行:
赫鲁库PS
紧接着,显示了一个崩溃
web.1:2018/12/09 11:24:35+0100(约4200万年前)崩溃
尝试使用以下命令迁移数据库:
heroku运行python manage.py migrate
现在让我知道,它缺少模块:dj database url
modulenotfounderror:没有名为“dj_database_url”的模块
不过,看看我的requirements.txt文件,这里的列表中显然有这个。
由于网络中的主要引用要么是检查它是否包含在requirements.txt文件中,gunicorn文件定义正确,要么是collectStatic被禁用-我不知所措,我希望有人能够帮助解决这个问题,同时也希望,上面的指针将有利于其他人。处理同样的早期问题。
我的文件如下:
进程文件
web: gunicorn learning_log.wsgi â-log-file -
procfile带有大写字母“p”,该应用程序称为learning_log
需求.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
WSG.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'
运行时间
Python 3.7.0
我真诚地希望,有人能在这里帮助我,我有点不知所措,可能还需要什么。
我希望这足以解释-我明白显然Heroku方面也有一些更新,但要了解这一点真的很困难。
多谢,
西蒙