A reusable Django rich text editor widget with image upload and XSS protection.
Project description
django-textedit
A reusable Django rich text editor widget with image upload, emoji picker, and XSS protection. No external dependencies.
Features
- WYSIWYG Editor : contenteditable-based, no external JS library
- Toolbar : bold, italic, underline, highlight, text color, uppercase, bullet lists (5 types), alignment, image insert, emoji insert
- Image Upload : drag & drop or file browser, with multi-layer server validation (extension, MIME, magic bytes, file size, filename sanitization)
- Emoji Picker : 7 categories (smileys, gestures, symbols, nature, food, travel, sport), 200+ emojis
- Image Resize : proportional resize handles on all 4 corners (mouse & touch)
- HTML Sanitizer : whitelist-based anti-XSS, automatic on save
- Responsive : mobile-first CSS with 3 breakpoints (mobile, tablet 768px+, desktop 1024px+)
- Django Admin : dedicated
AdminTextEditWidgetwith admin-specific CSS - CSRF Protected : image uploads use the CSRF token from cookie
Quick Start
pip install django-textedit
Add to INSTALLED_APPS:
INSTALLED_APPS = [
# ...
'textedit',
]
Configure media files in settings.py:
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'
Include URLs in your urls.py:
from django.urls import include, path
urlpatterns = [
path('textedit/', include('textedit.urls')),
]
Usage
Model
from django.db import models
from textedit.models import RichTextField
class Article(models.Model):
title = models.CharField(max_length=200)
content = RichTextField()
Form
from django import forms
from textedit.forms import TextEditFormField
from .models import Article
class ArticleForm(forms.ModelForm):
content = TextEditFormField()
class Meta:
model = Article
fields = ['title', 'content']
Template
<head>
{{ form.media }}
</head>
<body>
<form method="post">
{% csrf_token %}
{{ form.content }}
<button type="submit">Save</button>
</form>
</body>
Configuration
Optional settings in settings.py:
# Max upload size in bytes (default: 5 MB)
TEXTEDIT_MAX_UPLOAD_SIZE = 5 * 1024 * 1024
# Allowed image extensions
TEXTEDIT_ALLOWED_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.webp']
# Upload directory (relative to MEDIA_ROOT)
TEXTEDIT_UPLOAD_DIR = 'textedit_uploads'
Requirements
- Python >= 3.10
- Django >= 4.2
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_textedit-0.1.0.tar.gz.
File metadata
- Download URL: django_textedit-0.1.0.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80ca3cc5425bd62941e1c3dd43df221c5ef6471e742177ab401ec3e224b3d7ee
|
|
| MD5 |
4f1cab0ff3ba68ec40937c99a213b6b6
|
|
| BLAKE2b-256 |
0739dd9512cbc69e2c4e2e095edbb4508e7bb8e14bc6ae51b8f27b60c69f8af2
|
File details
Details for the file django_textedit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_textedit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3be4c420d744045667c885cfc067dc2d178ac6f78d7fe55165f6dd6d9b08ea41
|
|
| MD5 |
664b432a62e7a2be6e1534d0c9142155
|
|
| BLAKE2b-256 |
1358708e269f43f2e8802fe83bf50f44b32fc683f2dad9a630c1431cd31ca63c
|