将Django应用程序部署到Heroku时,我的日志中出现错误,但仅当使用django-ckeditor软件包时。 CKEditor在本地运行良好,早期版本的应用程序在CKEditor本地和Heroku 上均可正常运行,所以我知道这就是问题所在。我已经退步,无法弄清楚哪里出了问题。这是我的以下日志...
Heroku日志
2018-12-10T03:03:16.513649+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-12-10T03:03:16.513651+00:00 app[web.1]: return self.load_wsgiapp()
2018-12-10T03:03:16.513652+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-12-10T03:03:16.513654+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-12-10T03:03:16.513656+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2018-12-10T03:03:16.513657+00:00 app[web.1]: __import__(module)
2018-12-10T03:03:16.513659+00:00 app[web.1]: File "/app/JayNautic/wsgi.py", line 16, in <module>
2018-12-10T03:03:16.513660+00:00 app[web.1]: application = get_wsgi_application()
2018-12-10T03:03:16.513662+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
2018-12-10T03:03:16.513664+00:00 app[web.1]: django.setup(set_prefix=False)
2018-12-10T03:03:16.513665+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
2018-12-10T03:03:16.513667+00:00 app[web.1]: apps.populate(settings.INSTALLED_APPS)
2018-12-10T03:03:16.513669+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
2018-12-10T03:03:16.513670+00:00 app[web.1]: app_config = AppConfig.create(entry)
2018-12-10T03:03:16.513672+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
2018-12-10T03:03:16.513674+00:00 app[web.1]: module = import_module(entry)
2018-12-10T03:03:16.513675+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/importlib/__init__.py", line 127, in import_module
2018-12-10T03:03:16.513677+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2018-12-10T03:03:16.513718+00:00 app[web.1]: ModuleNotFoundError: No module named 'ckeditor'
2018-12-10T03:03:16.514092+00:00 app[web.1]: [2018-12-10 03:03:16 +0000] [10] [INFO] Worker exiting (pid: 10)
2018-12-10T03:03:16.517239+00:00 app[web.1]:
2018-12-10T03:03:16.518081+00:00 app[web.1]: [2018-12-10 03:03:16 +0000] [11] [INFO] Worker exiting (pid: 11)
2018-12-10T03:03:16.715563+00:00 app[web.1]: [2018-12-10 03:03:16 +0000] [4] [INFO] Shutting down: Master
2018-12-10T03:03:16.715764+00:00 app[web.1]: [2018-12-10 03:03:16 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-12-10T03:03:16.809999+00:00 heroku[web.1]: Process exited with status 3
2018-12-10T03:03:16.828149+00:00 heroku[web.1]: State changed from up to crashed
2018-12-10T03:03:17.686112+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=my-app.herokuapp.com request_id=7d25a9e7-76a0-4fd0-95c1-ecf0c01aa593 fwd="71.76.74.217" dyno=web.1 connect=5001ms service= status=503 bytes= protocol=https
我已经按照说明安装了django-ckeditor。
pip install django-ckeditor
然后我将其包含在settings.py文件的随附应用中,并添加了适当的静态字段。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'articles',
'ckeditor',
]...
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'assets'),
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
CKEDITOR_BASEPATH = "/static/ckeditor/ckeditor"
CKEDITOR_UPLOAD_PATH = "uploads/"
CKEDITOR_RESTRICT_BY_USER = True
CKEDITOR_CONFIGS = {
'default': {
'toolbar': 'Advanced',
'width': 758,
'height': 300,
},
}
将其导入到我的模型文件中,然后在需要的地方添加丰富文本字段。
models.py
from ckeditor.fields import RichTextField...
class Article(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
body = RichTextField()
最后,我添加了正确的'|安全”到模板中的必填字段。
article_detail.html
<p>{{article.body | safe}}</p>
这是我的 requirements.txt 文件,如果有帮助的话。
astroid==2.1.0
colorama==0.4.1
Django==2.1.4
django-ckeditor==5.6.1
django-js-asset==1.1.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
Pillow==5.3.0
pylint==2.2.2
pytz==2018.7
six==1.11.0
whitenoise==4.1.2
wrapt==1.10.11
gunicorn==19.9.0
我的运行时文件是python-3.7.1
,在heroku上可以接受。
所有这些之后,我还运行了python manage.py collectstatic
,它在我的本地服务器上运行良好。我搜索了该站点,发现的每个答案都与我未使用的CKEditorFileUploader有关。我将非常感谢能为我提供帮助的任何人,因为这是我完成本网站的最后一步。
答案 0 :(得分:0)
您必须将ckeditor_uploader添加到INSTALLED_APPS