Django Prose
Django Prose provides your Django applications with wonderful rich-text editing.
Requirements
- Python 3.6.2 or later
- Django 3.0 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:
- Set up the
MEDIA_ROOTof your Django project (example inprose_example/prose_example/settings.py)) - Include the Django Prose URLs (example in
prose_example/prose_example/urls.py) - (Optional) Set up a different Django storage to store your files (e.g. S3)
🔒 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
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.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-prose-1.0.0.tar.gz | 8.6 kB | Without provenance | Details for django-prose-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_prose-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_prose-1.0.0-py3-none-any.whl |
Total release size: 17.5 kB
Release files / django-prose-1.0.0.tar.gz
| Download URL | django-prose-1.0.0.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f3ba096ee923421bcdef4cbd42ae7ac8d6266548687151ae8fd1dc292e07aaa4
|
|
BLAKE2b-256 checksum How to use checksums |
e2b734ff7daa5d819fa1e52d7611771b32f5d0e328fec3c9271429055ca6f374
|
| 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.0.0-py3-none-any.whl
| Download URL | django_prose-1.0.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
34da4a7e700af06d8ef1ead07a8e87fde0990ca22834991eb5c7b5d03a695b91
|
|
BLAKE2b-256 checksum How to use checksums |
d588f162ebe7ad752151f67d89c7e846f1b39e58c6de6f716176985fa764b794
|
| 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.0.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.