EditorJS might give writers in your blog the same feel writers in medium get,more or less. Want to integrate Django and editorJS together for a blog or something similar? This article might help you.
Assumption : _You already have a Ajango project and a app where you are going to use editorjs
pip install django-editorjs
Now adddjango_editorjs to INSTALLED_APPS in settings.py (Note the underscore here)
Now before we create the model , let me inform you that to upload images you need to setup your own file uploading solution (I have covered that too !)
So here I will create a Post model where I will first import EditorJsField
_from django_editorjs import EditorJsField_
then I will create fields for Post, the body field will have EditorJsField .
Post model
But if you need to have images inside that post then :
Post Model with images for editorJs enabled
So in this model we have editorjs_config which will have custom settings for image.
1. I have two urls for byFile and byUrl fields in endpoints in config of Image. we will be creating those urls from scratch.
2. I also have additionalRequestHeaders field which has a array of objects ,though only one object is there . This object has :
Content-Type:’multipart/form-data’
This header is necessary for uploading images.
Images when uploaded to editorJS will be pushed to the server , if server returns success only then we can have that image in the editor space.
#django #web-development #python #programming #developer