Git Product home page Git Product logo

django-trix-editor's Introduction

Django Trix Editor Integration

This package provides a Django app that integrates the Trix editor with your Django project. Requires Django 4.1+

Installation

Install the package with pip:

pip install django-trix-editor

To change the version of Trix that is used, you can specify the version in your settings.py:

TRIX_VERSION = '2.0.0'

Usage

To use this package, you need to add it to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'trix_editor',
    ...
]

Don't forget to add the trix_editor urls to your urls.py to handle attachments:

from django.urls import include, path

urlpatterns = [
    ...
    path('trix-editor/', include('trix_editor.urls')),
    ...
]

If you want to give a specific permission to upload attachments, you can specify it in your settings.py:

TRIX_UPLOAD_PERMISSION = 'your_model.upload_attachment'

You can use the TrixEditorField in your models:

from django.db import models
from trix_editor.fields import TrixEditorField

class MyModel(models.Model):
    content = TrixEditorField()

Templates and forms

Customize your forms to use the widget TrixEditorWidget:

from django import forms
from trix_editor.widgets import TrixEditorWidget

class MyForm(forms.Form):
    content = forms.CharField(widget=TrixEditorWidget())

But don't forget to include the following statements to your template to load the Trix editor assets:

...
<head>
    <meta charset="utf-8">
    <title></title>
    ...
    {{ form.media.css }}
</head>
...
<!-- footer -->
{{ form.media.js }}

Django Admin Integration

To use the Trix editor in the Django admin, you need to add the following to your admin.py:

from django.contrib import admin
from django import forms

from trix_editor.widgets import TrixEditorWidget

class ContentForm(forms.ModelForm):
    class Meta:
        model = Content
        fields = ["title", "content", "status"]
        widgets = {
            "content": TrixEditorWidget(),
        }

@admin.register(Content)
class ContentAdmin(admin.ModelAdmin):
    list_display = ("title", "status", "created", "updated")
    form = ContentForm

django-trix-editor's People

Contributors

adilkhash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.