Skip to main content

django-simditor2

Installation

pip install django-simditor2

Add simditor to your INSTALLED_APPS setting.

from django.db import models
from simditor.fields import RichTextField


class Post(models.Model):
    content = RichTextField()

emoji

Markdown

Image upload config

drop image

clipboard image

urls.py

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^simditor/', include('simditor.urls'))   # add this line
]

settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'simditor'
]

SIMDITOR_UPLOAD_PATH = 'uploads/'
SIMDITOR_IMAGE_BACKEND = 'pillow'

SIMDITOR_TOOLBAR = [
    'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale',
    'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link',
    'image', 'hr', '|', 'indent', 'outdent', 'alignment', 'fullscreen',
    'markdown', 'emoji'
]

SIMDITOR_CONFIGS = {
    'toolbar': SIMDITOR_TOOLBAR,
    'upload': {
        'url': '/simditor/upload/',
        'fileKey': 'upload',
        'image_size': 1024 * 1024 * 4   # max image size 4MB
    },
    'emoji': {
        'imagePath': '/static/simditor/images/emoji/'
    }
}

the following settings only v0.2 support:

If you want to over the date_path format in upload_path:

# settings.py file:
SIMDITOR_UPLOAD_PATH = 'uploads/%Y%m%d/'  # or whatever datetime format you want

If you want to be able to have control over filename generation, you have to add a custom filename generator to your settings:

# create a file: utils.py, and define a function
def get_filename(filename, request):
    return filename.upper()  # or return whatever you want
# settings.py file:
SIMDITOR_FILENAME_GENERATOR = 'utils.get_filename'

without django admin demo

from django.views import generic
from django.views.decorators.csrf import csrf_exempt

from simditor.views import upload_handler


class ImageUploadView(generic.View):
    """ImageUploadView."""

    http_method_names = ['post']

    def post(self, request, **kwargs):
        """Post."""
        return upload_handler(request)


urlpatterns = [
    url(r'^$', IndexView.as_view(), name='simditor-form'),
    url(r'^simditor/upload', csrf_exempt(ImageUploadView.as_view())),
]
# IndexView
from django import forms

from django.views import generic

from simditor.fields import RichTextFormField
try:
    from django.urls import reverse
except ImportError:  # Django < 2.0
    from django.core.urlresolvers import reverse


class SimditorForm(forms.Form):
    content = RichTextFormField()


class IndexView(generic.FormView):
    form_class = SimditorForm

    template_name = 'index.html'

    def get_success_url(self):
        return reverse('simditor-form')

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <form method="post" action="./">
        {% csrf_token %}
        {{ form.media }}
        {{ form.as_p }}
        <p><input type="submit" value="post"></p>
    </form>
</body>
</html>

more detail you can check simditor_demo

Metadata

Release files for django-simditor2 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-simditor2 0.2
File Size Uploaded
django-simditor2-0.2.tar.gz 4.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-simditor2 0.2
File Interpreter ABI Platform
django_simditor2-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 MB

Release files / django-simditor2-0.2.tar.gz

Download URL django-simditor2-0.2.tar.gz
Size 4.2 MB
Tags Source
SHA-256 checksum
How to use checksums
fd8a99d9df93ccee15f2d75ed5ccd209c19fe272e2122605795b30a71bf4b0d3
BLAKE2b-256 checksum
How to use checksums
37da58e5d3ac9b0419b2c7b5a42840668f37b6b50df4ac7f5914fc9d49bc6660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / django_simditor2-0.2-py3-none-any.whl

Download URL django_simditor2-0.2-py3-none-any.whl
Size 4.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
123244a061c24d418ce92fd3cfb9ce864be63a407cea196972cc84ece14b0a8f
BLAKE2b-256 checksum
How to use checksums
00bfe254e0c1d2587cf0a5c4895cc051156021a4e949c6d4d7fdb9f157d3b67e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page