logo

Django Templates blog demo


This blog uses the Trix editor for its WYSIWYG (What You See Is What You Get) capabilities, accessible via the admin panel.

Why Use Trix?


The Trix editor, created by Basecamp, is simple and efficient. It offers a clean interface with essential tools for text formatting, such as bold, italic, and underline. You can also easily add links, lists, quotes, and embedded images or files by dragging and dropping them into your post.

Key Features

  1. User-Friendly: Trix is easy to use, with a straightforward toolbar that makes editing a breeze.
  2. Inline Formatting: Quickly apply text styles like bold, italic, and more.
  3. Link and Media Insertion: Add links and embed images or files effortlessly.
  4. Lists and Quotes: Create ordered/unordered lists and block quotes.
  5. Cross-Platform: Works seamlessly on all major browsers and devices.

Using Trix in Your Blog


To start using Trix, log in to the admin panel and open the blog editor. The Trix editor ensures that what you see while editing is what your readers will see once published.

django-development.png 369.54 KB


Quick Integration Example


Include Trix in your HTML
:

html
Copy code<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.1/trix.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/trix/1.3.1/trix.js"></script>


Add Trix to Your Template
:

html
Copy code<form method="post">
  {% csrf_token %}
  <input id="trix-editor" type="hidden" name="content">
  <trix-editor input="trix-editor"></trix-editor>
  <button type="submit">Save</button>
</form>


Handle Trix Data in Your Django View
:

python
Copy codefrom django.shortcuts import render, redirect
from .models import BlogPost

def create_post(request):
    if request.method == "POST":
        content = request.POST['content']
        new_post = BlogPost(content=content)
        new_post.save()
        return redirect('post_list')
    return render(request, 'create_post.html')


Using Trix makes writing and editing blog posts easy and efficient, so you can focus on creating great content.