Skip to main content

Trix rich text editor widget for Django (Fork of https://github.com/tortillagroup/django-trix)

Project description

django-trix

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

Installation

  1. From PyPI:

    pip install django-trix-fork

  2. Install trix as app in django Add to INSTALLED_APPS:

    INSTALLED_APPS = (
        ...
        'trix',
        ...
    )
    
  3. Add route to urls.py:

    urlpatterns = [
        ...
        url(r'^trix/', include('trix.urls')),
        ...
    ]
    
  4. Add django-trix variables to your app/settings.py:

    ...
    # valid file extentions for attachment 
    TRIX_EXTENSIONS = ['.jpg', '.png'] 
    
    # folder where attachments will be saved
    TRIX_URI = 'trix' 
    ...
    
  5. Set-Up trix-django tables:

    python manage.py makemigrations trix
    python manage.py migrate
    

Done

How to use 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.

What Works

Basically Everything :) from Rich Text formatting to Uploading Attachments !

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-fork-0.3.1.2.tar.gz (105.1 kB view details)

Uploaded Source

Built Distribution

django_trix_fork-0.3.1.2-py3-none-any.whl (107.8 kB view details)

Uploaded Python 3

File details

Details for the file django_trix-fork-0.3.1.2.tar.gz.

File metadata

  • Download URL: django_trix-fork-0.3.1.2.tar.gz
  • Upload date:
  • Size: 105.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for django_trix-fork-0.3.1.2.tar.gz
Algorithm Hash digest
SHA256 8412c01d9f52652908f665a4118a6a9c1bb85a6c4e65b39bd381a68ef348ef16
MD5 4428ad73c1e79a1e7399a14c0cd9d0a3
BLAKE2b-256 897e421a300330f0fe6e3023cb49715d4353e73040999e8dd7de161c4a6e8bb7

See more details on using hashes here.

File details

Details for the file django_trix_fork-0.3.1.2-py3-none-any.whl.

File metadata

  • Download URL: django_trix_fork-0.3.1.2-py3-none-any.whl
  • Upload date:
  • Size: 107.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5

File hashes

Hashes for django_trix_fork-0.3.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ca6c75856c792dc636009ba43702f7f7f02f3309033d9bb61e529fa0eb062844
MD5 86d0860ca6f29dbc5e7c21a9d87c6245
BLAKE2b-256 01968bdcd21014d9c7a65f1968d1ef45862f68c746c35401fef744db10171ae8

See more details on using hashes here.

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