Add ckeditor into django app
CKEditor - rich text field
[ ]
pip install django-ckeditor[ ]
add this inside models.py
from ckeditor.fields import RichTextField content = RichTextField(null=True, blank=True) # add this # content = models.TextField(null=True, blank=True) # instead of this
[ ]
python manage.py makemigrations[ ]
python manage.py migrate[ ]
add 'ckeditor' to settings.py installed apps[ ]
add some config to give the editor more functionality. Inside settings.py
CKEDITOR_CONFIGS = { 'default': { 'toolbar': 'full', 'height': 300, 'width': '100%', 'skin': 'moono', 'extraPlugins': ','.join( [ 'codesnippet', ]), }, }
[ ]
All blocks where Richtextfield was used, add |safe at the end, like so:
<p>{{project.content|safe}}</p>
Now go to base.html (head section) and add this to get syntax highlighting in the browser. using highlight.js learned from this - Django - CKEditor Tutorial (+ CodeSnippet) video
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/styles/base16/zenburn.min.css"> <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/highlight.min.js"></script> <script>hljs.highlightAll();</script>