Skip to main content

django-editorjs-fields

Django integration for Editor.js — a block-style WYSIWYG editor.

  • Django: 2.2 – 6.x
  • Python: 3.8 – 3.13
  • Editor.js: 2.31.6
  • PyPI Downloads

Django Editor.js


Table of Contents


Installation

pip install django-editorjs-fields

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'django_editorjs_fields',
]

Upgrade

pip install django-editorjs-fields --upgrade
python manage.py collectstatic

Quick start

Define fields in your model:

from django.db import models
from django_editorjs_fields import EditorJsJSONField, EditorJsTextField


class Post(models.Model):
    # Stores data as JSON (Django >= 3.1)
    body = EditorJsJSONField(null=True, blank=True)

    # Stores data as serialized JSON string (any Django version)
    body_text = EditorJsTextField(null=True, blank=True)

Don't forget to add URLs for image upload and link metadata:

# urls.py
from django.urls import path, include

urlpatterns = [
    # ...
    path('editorjs/', include('django_editorjs_fields.urls')),
]

See the full example project: example/


Rendering in templates

Use the editorjs template filter to render stored blocks as HTML:

{% load editorjs %}
{{ post.body|editorjs }}

The filter escapes all user content to prevent XSS. Use the raw block type if you need to render trusted HTML.


Field arguments

Both EditorJsJSONField and EditorJsTextField accept all arguments of their base Django fields (JSONField / TextField) plus:

Argument Description Default
plugins List of Editor.js plugin packages EDITORJS_DEFAULT_PLUGINS
tools Tool configuration map (docs) EDITORJS_DEFAULT_CONFIG_TOOLS
config Editor.js config overrides (autofocus, readOnly, placeholder, etc.) {}

Config keys are passed directly to the Editor.js constructor. Refer to the official docs for all options.


Custom plugins

Pass a custom plugin list and tool configuration to the field:

body = EditorJsJSONField(
    plugins=[
        "@editorjs/image",
        "@editorjs/header",
        "@editorjs/code@2.6.0",      # pin a specific version
        "@editorjs/list@latest",
        # Full URLs work for plugins hosted outside npm/jsDelivr
        "https://cdn.jsdelivr.net/gh/some-repo/plugin@main/index.js",
    ],
    tools={
        "Image": {
            "config": {
                "endpoints": {
                    "byFile": "/my-upload-endpoint/"
                }
            }
        },
    },
    config={"minHeight": 500},
)

Registering custom plugin keys

If your custom plugin is not in the built-in PLUGINS_KEYS map, register it in settings:

# settings.py
EDITORJS_PLUGINS_KEYS = {
    'my/custom-plugin': 'MyCustomPlugin',
}

This map is merged with built-in defaults — you only need entries for your own plugins.

Built-in plugins

The following plugins are enabled by default:

EDITORJS_DEFAULT_PLUGINS
(
    '@editorjs/paragraph',
    '@editorjs/image',
    '@editorjs/header',
    '@editorjs/list',
    '@editorjs/checklist',
    '@editorjs/quote',
    '@editorjs/raw',
    '@editorjs/code',
    '@editorjs/inline-code',
    '@editorjs/embed',
    '@editorjs/delimiter',
    '@editorjs/warning',
    '@editorjs/link',
    '@editorjs/marker',
    '@editorjs/table',
)
EDITORJS_DEFAULT_CONFIG_TOOLS
{
    'Image': {
        'class': 'ImageTool',
        'inlineToolbar': True,
        "config": {
            "endpoints": {
                "byFile": reverse_lazy('editorjs_image_upload'),
                "byUrl": reverse_lazy('editorjs_image_by_url')
            }
        },
    },
    'Header': {
        'class': 'Header',
        'inlineToolbar': True,
        'config': {
            'placeholder': 'Enter a header',
            'levels': [2, 3, 4],
            'defaultLevel': 2,
        }
    },
    'Checklist': {'class': 'Checklist', 'inlineToolbar': True},
    'List': {'class': 'EditorjsList', 'inlineToolbar': True},
    'Quote': {'class': 'Quote', 'inlineToolbar': True},
    'Raw': {'class': 'RawTool'},
    'Code': {'class': 'CodeTool'},
    'InlineCode': {'class': 'InlineCode'},
    'Embed': {'class': 'Embed'},
    'Delimiter': {'class': 'Delimiter'},
    'Warning': {'class': 'Warning', 'inlineToolbar': True},
    'LinkTool': {
        'class': 'LinkTool',
        'config': {
            'endpoint': reverse_lazy('editorjs_linktool'),
        }
    },
    'Marker': {'class': 'Marker', 'inlineToolbar': True},
    'Table': {'class': 'Table', 'inlineToolbar': True},
}

Forms and widgets

Use EditorJsWidget in forms:

from django import forms
from django_editorjs_fields import EditorJsWidget


class PostForm(forms.ModelForm):
    class Meta:
        model = Post
        fields = '__all__'
        widgets = {
            'body': EditorJsWidget(
                plugins=["@editorjs/image", "@editorjs/header"],
                config={'minHeight': 200},
            )
        }

Image uploads

Include the package URLs (see Quick start). Images are saved to MEDIA_ROOT/uploads/images/YYYY/MM/ by default.

In development (DEBUG=True), also serve media files:

# urls.py
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

In production, configure your web server (nginx, Apache) to serve MEDIA_URL.


Dark theme

The editor adapts to the system dark mode via prefers-color-scheme. In Django admin (4.2+), it also respects the theme toggle button (data-theme="dark").


Settings

All settings go in your project's settings.py.

Setting Description Default Type
EDITORJS_DEFAULT_PLUGINS Plugin package list See above list, tuple
EDITORJS_DEFAULT_CONFIG_TOOLS Tool configuration map See above dict
EDITORJS_PLUGINS_KEYS Custom plugin → tool key map (merged with defaults) {} dict
EDITORJS_VERSION Editor.js version '2.31.6' str
EDITORJS_IMAGE_UPLOAD_PATH Base upload directory 'uploads/images/' str
EDITORJS_IMAGE_UPLOAD_PATH_DATE Date subdirectory format '%Y/%m/' str
EDITORJS_IMAGE_NAME_ORIGINAL Keep original filename False bool
EDITORJS_IMAGE_NAME Filename generator callable token_urlsafe(8) callable
EDITORJS_EMBED_HOSTNAME_ALLOWED Allowed hostnames for embed validation See source list, tuple

Support

Report issues on GitHub

Metadata

Release files for django-editorjs-fields 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-editorjs-fields 0.3.0
File Size Uploaded
django_editorjs_fields-0.3.0.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-editorjs-fields 0.3.0
File Interpreter ABI Platform
django_editorjs_fields-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.9 kB

Release files / django_editorjs_fields-0.3.0.tar.gz

Download URL django_editorjs_fields-0.3.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
aedeefb20fde20a70ed4041dcc34b1c485e6e1f25ea671d3a00ebad3720e4a86
BLAKE2b-256 checksum
How to use checksums
473a16fbbfa5e382fbe77b2bcbd583beca9b3d3bb58df7f97f4f9db303d643af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.11 Linux/6.12.94+deb13-amd64

Release files / django_editorjs_fields-0.3.0-py3-none-any.whl

Download URL django_editorjs_fields-0.3.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d01f0d031cca2a539d14993fdb580ee0118fcb3ffcd542c21f41b80203728265
BLAKE2b-256 checksum
How to use checksums
6c78db8068b263612295c49a542c99427a56e2edf30568c6d2f557effc53e7f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.12.11 Linux/6.12.94+deb13-amd64

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page