Skip to main content

Django Prose

PyPI - Downloads PyPI - Python Version

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

Requirements

  • Python 3.8 or later
  • Django 3.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: example/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.

Rendering rich-text in templates

Rich text content essentially is HTML. For this reason it needs to be manually marked as safe, when rendered in Django templates. Example:

{{ document.content | safe}}

Small rich-text content

You might want to add rich-text content 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()

As mentioned above, you need to mark the article excerpt as safe, in order to render it:

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

Large rich-text content

In case you want to store large rich-text content, like the body 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 content 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 as well, you need to mark the article's body as safe, in order to render it:

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

Forms with rich-text editing

You can create forms for your Django Prose models, to provide rich-text editing functionality. In that case, you will also need to render form.media, to load Trix with its stylesheets.

<form  method="POST" >
  {% csrf_token %}
  
  {{ form.as_p }}
  {{ form.media }}
  
  <button type="submit">Submit</button>
</form>

The same is true also, if you are rendering the forms field manually.

Attachments

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

Full example

You can find a full example of a blog, built with Django Prose in the example directory.

🔒 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

Real world use cases

  • Remote Work Café: Used to edit location pagess, like Amsterdam | Remote Work Café
  • In production by multiple clients of LOGIC, from small companies to the public sector.

If you are using Django Prose in your application too, feek free to open a Pull Request to include it here. We would love to have it.

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 and Development Containers.

To get started run these commands in the provided order:

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

If you are using Visual Studio code, just open this repository in a container using the Dev Containers: Open Folder in Container.


🦄 Built with LOGIC. 🦄

Metadata

Release files for django-prose 1.2.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.2.0
File Size Uploaded Provenance Actions
django_prose-1.2.0.tar.gz 9.8 kB Without provenance Details for django_prose-1.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 19.2 kB

Release files / django_prose-1.2.0.tar.gz

Download URL django_prose-1.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d1b887f0950ed99f133d0520a2554dcad35c7021d05d05db975e4d502272e569
BLAKE2b-256 checksum
How to use checksums
2f2c730355d8c254e17323018d46c906558f6b2f18f895ad697a8162b2eda19e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

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

Download URL django_prose-1.2.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aef7f5330ea3d0c6f3a2725de8e458739d5c015db7d823d0857745d61f7c17fc
BLAKE2b-256 checksum
How to use checksums
ec4b25220ed920b802e27831b8a149dc2f57412942e1b7f21bbf69b755f7ecdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

Security for django-prose 1.2.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