Skip to main content

Django Prose

PyPI - Downloads PyPI - Python Version

Django Prose provides your Django applications with wonderful rich-text editing.

Requirements

  • Python 3.6.2 or later
  • Django 2.2 or later
  • Bleach 4.0 or later

Getting started

To get started with Django Prose, first make sure to install it. We use and suggest using Poetry, although Pipenv and pip will work seamlessly as well

poetry add django-prose

Then, add prose in Django's installed apps (example: prose_example/prose_example/settings.py):

INSTALLED_APPS = [
    # Django stock apps (e.g. 'django.contrib.admin')

    'prose',

    # your application's apps
]

Last, run migrations so you can use Django Prose's Document model:

python manage.py migrate prose

Now, you are ready to go 🚀.

Usage

There are different ways to use Django prose according to your needs. We will examine all of them here.

Small rich-text information

You might want to add rich-text information in a model that is just a few characters (e.g. 140), like an excerpt from an article. In that case we suggest using the RichTextField. Example:

from django.db import models
from prose.fields import RichTextField

class Article(models.Model):
    excerpt = RichTextField()

Then you can display the article excerpt in your HTML templates by marking it as safe

<div class="article-excerpt">{{ article.excerpt | safe}}</div>

Large rich-text information

In case you want to store large rich-text information, like the content of an article, which can span to quite a few thousand characters, we suggest you use the AbstractDocument model. This will save large rich-text information in a separate database table, which is better for performance. Example:

from django.db import models
from prose.fields import RichTextField
from prose.models import AbstractDocument

class ArticleContent(AbstractDocument):
    pass

class Article(models.Model):
    excerpt = RichTextField()
    body = models.OneToOneField(ArticleContent, on_delete=models.CASCADE)

Similarly here you can display the article's body by marking it as safe

<div class="article-body">{{ article.body.content | safe}}</div>

Attachments

Django Prose can also handle uploading attachments with drag and drop. To set this up, first you need to:

🔒 A note on security

As you can see in the examples above, what Django Prose does is provide you with a user friendly editor (Trix) for your rich text content and then store it as HTML in your database. Since you will mark this HTML as safe in order to use it in your templates, it needs to be sanitised, before it gets stored in the database.

For this reason Django Prose is using Bleach to only allow the following tags and attributes:

  • Allowed tags: p, ul, ol, li, strong, em, div, span, a, blockquote, pre, figure, figcaption, br, code, h1, h2, h3, h4, h5, h6, picture, source, img
  • Allowed attributes: alt, class, id, src, srcset, href, media

Screenshots

Django Prose Documents in Django Admin

Django Prose Document in Django Admin

Development for Django Prose

If you plan to contribute code to Django Prose, this section is for you. All development tooling for Django Prose has been set up with Docker. To get started run these commands in the provided order:

docker compose run --rm migrate
docker compose run --rm createsuperuser
docker compose up

🦄 Built with ❤️ by LOGIC. 🦄

Metadata

Release files for django-prose 1.1.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-prose 1.1.0
File Size Uploaded Provenance Actions
django-prose-1.1.0.tar.gz 8.6 kB Without provenance Details for django-prose-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-prose 1.1.0
File Interpreter ABI Platform Actions
django_prose-1.1.0-py3-none-any.whl Python 3 none any Details for django_prose-1.1.0-py3-none-any.whl

Total release size: 17.5 kB

Release files / django-prose-1.1.0.tar.gz

Download URL django-prose-1.1.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9c9a6cdafbc375fa82200b85d4b046d4e78d5f6cdb0a69148a7ae67eafe0aef5
BLAKE2b-256 checksum
How to use checksums
c74ca62c980ad3f96bc45092438ea243d93af992669a5e04e31d0e73a363a719
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.13.0-1021-azure

Release files / django_prose-1.1.0-py3-none-any.whl

Download URL django_prose-1.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e8107bb1fdb1d6ea03129fa36c76cae742654606ca381f4d392ee7285afaf1a
BLAKE2b-256 checksum
How to use checksums
26862bf4697cd6f889ca00a2914b6a939c5bfee9a7e40416013279ee65ce5925
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.8.10 Linux/5.13.0-1021-azure

Security for django-prose 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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