Skip to main content

Safe and minimal integration of Quill editor in Django using JSON delta format only.

Project description

django-quill-safe

A simple and secure integration of the Quill rich text editor into Django projects, using the Quill Delta JSON format.

Features

  • Secure Content Storage: Stores and validates Quill Delta JSON in the database, not unsafe raw HTML.
  • Intuitive Integration: Simple to integrate into any Django model with the QuillField.
  • Form Handling: A dedicated QuillFormField and widget for seamless form handling.
  • Read-Only Display: A quill_display template tag for safely rendering content in read-only views.
  • Bundled Assets: Includes Quill 2.0.3 assets for easy static file integration.
  • Multiple Editor Support: Safely handles multiple Quill editors on a single page/form without conflicts.

Installation

pip install django-quill-safe

Add 'quillsafe' to your project's INSTALLED_APPS in settings.py:

INSTALLED_APPS = [
    # ... other apps
    'quillsafe',
]

Usage

1. Model Field

To store the rich text content in your database, use the QuillField in your Django model. This field is essential as it handles the secure serialization and deserialization of the Quill delta JSON.

from django.db import models
from quillsafe.fields import QuillField

class Article(models.Model):
    title = models.CharField(max_length=255)
    content = QuillField()

    def __str__(self):
        return str(self.title)

2. Forms

Use the QuillFormField in your Django forms to safely handle Quill's JSON delta content. This form field can be rendered just like any other Django form field.

from django import forms
from quillsafe.fields import QuillFormField

class ArticleForm(forms.Form):
    content = QuillFormField()

The form can then be rendered in your template using standard Django template tags:

{{ form }}
{{ form.as_p }}
{{ form|crispy }}

3. Enabling the Editor UI

To enable the Quill editor UI in your templates, you must load the necessary CSS and JS assets. You have two options:

  • Use the included static files: This library includes Quill version 2.0.3. The assets are bundled with the package and can be loaded using Django's {% static %} template tag.

  • Use a CDN: You can also replace the local files with a direct CDN link if you prefer.

{% load static %}

<link
    href="{% static 'quillsafe/quill.snow.min.css' %}"
    rel="stylesheet"
/>
<script src="{% static 'quillsafe/quill.min.js' %}"></script>

4. Displaying Content in a Read-Only View

To display the stored Quill delta content safely as HTML on templates, use the quill_display template tag. This tag renders the content within a read-only Quill editor, populating the data without any menu controls.

First, load the tag in your template and then use it as follows:

{% load quill_tags %}
{% quill_display article.content %}

Data Handling & Security

The QuillField stores content in the JSON delta format, not raw HTML. This design is crucial for security as it prevents unvalidated HTML from being stored directly in your database. You can access and manipulate the raw delta JSON directly from your views or models if needed.

Documentation

For more detailed documentation, please visit: https://djangoquillsafe.readthedocs.io

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_quill_safe-0.1.2.tar.gz (131.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_quill_safe-0.1.2-py3-none-any.whl (142.5 kB view details)

Uploaded Python 3

File details

Details for the file django_quill_safe-0.1.2.tar.gz.

File metadata

  • Download URL: django_quill_safe-0.1.2.tar.gz
  • Upload date:
  • Size: 131.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.2 Linux/6.1.0-39-amd64

File hashes

Hashes for django_quill_safe-0.1.2.tar.gz
Algorithm Hash digest
SHA256 29edc297e7832f8ed11ca70fbf1308d9b7d395c665fc0edbf35bc56193de66f9
MD5 c4f46d93f42fcbb8e7157b114c5aa9df
BLAKE2b-256 ee50742ed5183d9c8e608c47e0d1b7ec20242a9139476c5b8f777e2deccf54b4

See more details on using hashes here.

File details

Details for the file django_quill_safe-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: django_quill_safe-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 142.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.2 Linux/6.1.0-39-amd64

File hashes

Hashes for django_quill_safe-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2163b5f51180eecfa1d53520e03ff3c55395b1f0128436f2bb8df812c1650877
MD5 38fa245d80455602f487a43a5a8542a9
BLAKE2b-256 1ac6720b5a9811cd8bdf040c006e6b2eed5d6cba9e97af67b7ccc846ff62f17b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page