Skip to main content

Trix rich text editor widget for Django, using Trix 0.10.1.

https://circleci.com/gh/istrategylabs/django-trix/tree/master.svg?style=shield

Using django-trix

django-trix includes a form widget, a model field, and a model admin mixin that enables the rich text editor. You can use any of these methods, but you do not need to use all.

Model

To enable the editor in the Django admin (or any form) via the model field, use the Trix model field TrixField which inherits from django.db.models.TextField:

from django.db import models
from trix.fields import TrixField

class Post(models.Model):
    content = TrixField('Content')

Admin

To enable the editor in the Django admin, inherit from TrixAdmin and set the trix_fields attribute to a list of the fields that use an editor:

from myawesomeblogapp.models import Post
from trix.admin import TrixAdmin

@admin.register(Post)
class PostAdmin(TrixAdmin, admin.ModelAdmin):
    trix_fields = ('content',)

Forms and Templates

The editor can be used in forms and templates by adding the TrixEditor widget to a form field:

from django import forms
from trix.widgets import TrixEditor

class EditorForm(forms.Form):
    content = forms.CharField(widget=TrixEditor)

In the template, just use the form as you normally would, but be sure to include the associated media:

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Trix Editor Test</title>
        {{ form.media.css }}
    </head>
    <body>
        <form>
            {{ form }}
        </form>
        {{ form.media.js }}
    </body>
</html>

CSS in head, JS at end of body, because you are a responsible developer.

Installation

It’s on PyPI:

pip install django-trix

Add to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'trix',
    ...
)

Add route to urls.py:

urlpatterns = [
    ...
    url(r'^trixorwhateveryouwant/', include('trix.urls')),
    ...
]

TODO

  • A bunch of stuff!

  • Attachment uploads

Release files for django-trix 0.3.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-trix 0.3.0
File Size Uploaded
django-trix-0.3.0.tar.gz 92.5 kB Details

Release files / django-trix-0.3.0.tar.gz

Download URL django-trix-0.3.0.tar.gz
Size 92.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6672748af9cd3e8e8c6fbbb995a61c2781db82ccfd5064c2f9f26ce39924566b
BLAKE2b-256 checksum
How to use checksums
6f85144453f5f73d7688be08d2fd5ecbd86eb682216fab6282529872d9072ccc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1

1 release file

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