Skip to main content

Django EditorJS Field

Code style: black

Django >4.* (Not tested in old versions)

An EditorJS Field with dependency injection of tools support for Django >4.*

Features

  • Dependency injection for tools
  • Templatetag support
  • All EditorJS configuration supported
  • Without custom backend
  • Customized editor in admin
  • Debug support

Installation and Usage

Installation

Some day it will be django-editorjs-field...

Install package via pip:

pip install django-editorjs-field-next

Add package to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "django_editorjs_field"
]

Usage

Note!
If you will not provide configuration, you will have only default Paragraph Tool.

Example of field configuration:

from django_editorjs_field.tool import EditorJSTool as Tool


EditorJSField(
    tools=[
        Tool(name="Header", url="//cdn.jsdelivr.net/npm/@editorjs/header", template_name="tools/h.html"),
        Tool(
            name="Code",
            url="https://cdn.jsdelivr.net/npm/@editorjs/code@2.8.0",
            class_name="CodeTool",
            template_name="tools/code.html"
        )
    ]
)

Any kwargs that you add will pass to EditorJS configuration. For example, if you want autofocus, placeholder and i18n, you just add to field arguments:

autofocus=False,
placeholder="EditorJSPlaceholder",
i18n={
    "messages": {
        "toolNames": {
            "Heading": "Заголовок"
        }
    }
}

templatetag

Example of templatetag:

{% load editorjs %}

{% for article in articles_list %}
    <div>
        <h3>{{ article.title }}</h3>
        {% render article %}
    </div>
{% endfor %}

Tools

All tools (plugins) are independent objects. Tool constructor define as:

def __init__(self, name: str, url: str, template_name: str, class_name: str | None = None, **kwargs):
    """
        An EditorJSTool constructor

        ...

        Attributes
        ==========
        name : str
            Must be unique!
            A name of a Tool. Used as a type in EditorJS.
        url : str
            A URL or Path to JS-file of Tool.
        template_name : str
            A Path to template for output rendering.
        class_name : str | None
            Name attribute is used by default.
            A class name of Tool, which JS need to call constructor for.
        version : str | None
            Required plugin version.
    """

Override Paragraph Tool

In order to override Paragraph Tool you need to pass it as a tool into field. Example:

from django_editorjs_field.tool import EditorJSTool as Tool


EditorJSField(
    tools=[
        Tool(
            name="paragraph",
            url="//cdn.jsdelivr.net/npm/@editorjs/paragraph@2.0.2",
            class_name="Paragraph",
            template_name="tools/p.html"
        )
        Tool(name="Header", url="//cdn.jsdelivr.net/npm/@editorjs/header", template_name="tools/h.html"),
    ],
    ...
)

License

MIT

Authors

Evgeniy Gribanov

FAQ

About Debug support

If you run Django in DEBUG mode, your EditorJS inherit this mode too. It means that you will have usefull messages in your browser console about Editor Configuration and work.

Metadata

Release files for django-editorjs-field-next 0.1.2

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-field-next 0.1.2
File Size Uploaded
django_editorjs_field_next-0.1.2.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-editorjs-field-next 0.1.2
File Interpreter ABI Platform
django_editorjs_field_next-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.3 kB

Release files / django_editorjs_field_next-0.1.2.tar.gz

Download URL django_editorjs_field_next-0.1.2.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6fcfd05beef13c66d589e3385ecdad1a206924c520d400f8dab7a4bd24d16806
BLAKE2b-256 checksum
How to use checksums
b7419bc45e2b421164c0db9b7a41135fdd96be2de637d83e140fd6feb8075986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure

Release files / django_editorjs_field_next-0.1.2-py3-none-any.whl

Download URL django_editorjs_field_next-0.1.2-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebff2145962d6e337f66c657021533da2aed486224bd1d5b25aee3c47a06f204
BLAKE2b-256 checksum
How to use checksums
580c656563bd6d5bc71d80619629cddf0f3ef704f0f998e9c5d1cd1411d64580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.1 CPython/3.11.1 Linux/5.15.0-1024-azure

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

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