Skip to main content

Trix rich text editor widget for Django

Project description

Trix rich text editor widget for Django.

Uses Trix 0.9.

Using django-trix

django-trix includes both a form widget and a model admin mixin that enables the rich text editor.

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

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-trix-0.2.3.tar.gz (89.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page