I'm getting an error in my logs when deploying my Django application to Heroku, but only when using the django-ckeditor package. CKEditor runs just fine locally, and earlier versions of the application work fine both locally and on Heroku without CKEditor, so I know that's the problem. I've retraced my steps and can't figure out where I went wrong. Here are my following logs...
Heroku Logs
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
I've installed django-ckeditor according to the instructions.
pip install django-ckeditor
I then included it in my included apps for the settings.py file, and added the proper static fields.
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,
},
}
Imported it into my models file then added the richtextfields where necessary.
models.py
from ckeditor.fields import RichTextField...
class Article(models.Model):
title = models.CharField(max_length=100)
slug = models.SlugField()
body = RichTextField()
Finally I added the proper '| safe' to the necessary fields in the template.
article_detail.html
<p>{{article.body | safe}}</p>
And here's my requirements.txt file if that helps.
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
And my runtime file is python-3.7.1
, which is accepted on heroku.
I also ran python manage.py collectstatic
after all of this and it works perfectly on my local server. I searched this site and every answer I'm finding has to do with CKEditorFileUploader, which I'm not using. I would be very grateful to anyone that can help me with this as it is the very last piece I need to complete this website.
you have to add 'ckeditor_uploader' to INSTALLED_APPS