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.1.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.1-py3-none-any.whl (142.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_quill_safe-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 3e84a343f377fbde0e282f4b492db43e77c3f7fd10bdb46d0bd922a887987989
MD5 1c93f175ead946a83ced324bc4238251
BLAKE2b-256 35910bfe1df85b879217f14707569d42ce2ccc7f2cbd0efa54dc1bca600335be

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_quill_safe-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4692fe3cee98cfbfb26a45dd991624b2659d2be5e88093d50589db41f23000
MD5 bed478bac746b6f04d3a176a532261ef
BLAKE2b-256 87b08dc93cff1519d0d5429bfb0362323180d2bc624801468015a55d3c66ea47

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