Skip to main content

Rich text editor for Django with image upload, AI assistant, and inline formatting

Project description

Django Visual Editor

A rich text editor for Django with a clean document-style interface, AI assistant, and mobile support.

Features

  • Rich text editing — single contenteditable document with persistent toolbar
  • Formatting — bold, italic, underline, strikethrough, headings, bullet/numbered lists, blockquote, code block, inline code, links
  • HTML source mode — switch between visual and raw HTML editing
  • Fullscreen mode — distraction-free writing
  • AI assistant — right-side panel with selection editing, "Replace" / "Insert after" actions, and undo snapshots
  • Mic dictation — Web Speech API in the AI panel (requires HTTPS)
  • Mobile-friendly — responsive toolbar with large touch targets
  • Multi-provider AI — OpenAI, Groq, OpenRouter, Yandex GPT, or any OpenAI-compatible API

Installation

pip install django-visual-editor

# With AI support
pip install django-visual-editor[ai]

Setup

Add to settings.py:

INSTALLED_APPS = [
    ...
    'django_visual_editor',
]

MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'media'

Add to urls.py:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    ...
    path('editor/', include('django_visual_editor.urls')),
]

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Run migrations:

python manage.py migrate

Usage

Model field (recommended)

from django_visual_editor import VisualEditorField

class BlogPost(models.Model):
    title = models.CharField(max_length=200)
    content = VisualEditorField()

Widget

from django_visual_editor import VisualEditorWidget

class BlogPostForm(forms.ModelForm):
    class Meta:
        model = BlogPost
        fields = ['title', 'content']
        widgets = {
            'content': VisualEditorWidget(config={'placeholder': 'Start writing...'}),
        }

Template

<div>{{ post.content|safe }}</div>

<form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    {{ form.media }}
    <button type="submit">Save</button>
</form>

AI Assistant (optional)

VISUAL_EDITOR_AI_CONFIG = {
    'enabled': True,
    'default_model': 'gpt-4o',
    'models': [
        {
            'id': 'gpt-4o',
            'name': 'GPT-4o',
            'provider': 'OpenAI',
            'model': 'gpt-4o',
            'api_key': os.environ.get('OPENAI_API_KEY'),
            'base_url': None,
        },
        {
            'id': 'llama',
            'name': 'Llama 4 Scout',
            'provider': 'OpenRouter',
            'model': 'meta-llama/llama-4-scout:free',
            'api_key': os.environ.get('OPENROUTER_API_KEY'),
            'base_url': 'https://openrouter.ai/api/v1',
        },
    ],
}

Select text in the editor and click ✦ Ask AI to edit the selection. The AI panel shows a preview before applying changes. Use the ↩ button to undo AI edits (up to 10 snapshots).

Development

git clone https://github.com/hvlads/django-visual-editor.git
cd django-visual-editor

pip install -e ".[ai]"

cd frontend
npm install
npm run build
# or: npm run dev  (watch mode)

Cleanup images

python manage.py cleanup_editor_images --dry-run
python manage.py cleanup_editor_images

License

MIT

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_visual_editor-0.7.0.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_visual_editor-0.7.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

Details for the file django_visual_editor-0.7.0.tar.gz.

File metadata

  • Download URL: django_visual_editor-0.7.0.tar.gz
  • Upload date:
  • Size: 30.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for django_visual_editor-0.7.0.tar.gz
Algorithm Hash digest
SHA256 8559ff3aedb5ac0de9a34d8afe228166f9a21097eed85e4f74b75447ad20fce7
MD5 47bec482645f4a7d5dd314effa714454
BLAKE2b-256 0c653e252f8efd95019e1b981efcd3f309ad6a7f7fd69fd70db9904b80b9ab74

See more details on using hashes here.

File details

Details for the file django_visual_editor-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_visual_editor-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b9ba46a522caa7fce6f632d42a4ed7f35e6be6f9dd0f9c4a8cc3d6d2d50c534
MD5 e6eb29217dafd42f4ac04103f38b9a47
BLAKE2b-256 c255bb1d2202452c7f722dd1e2c91900c47bd4d31b92a5ed85af8a2e8f87b3a2

See more details on using hashes here.

Supported by

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