Skip to main content

A Django admin Simditor integration.

Project description

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

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-simditor2-0.2.tar.gz (4.2 MB view details)

Uploaded Source

Built Distribution

django_simditor2-0.2-py3-none-any.whl (4.4 MB view details)

Uploaded Python 3

File details

Details for the file django-simditor2-0.2.tar.gz.

File metadata

  • Download URL: django-simditor2-0.2.tar.gz
  • Upload date:
  • Size: 4.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.5

File hashes

Hashes for django-simditor2-0.2.tar.gz
Algorithm Hash digest
SHA256 fd8a99d9df93ccee15f2d75ed5ccd209c19fe272e2122605795b30a71bf4b0d3
MD5 d50dd8c93b757cb030a578608ee0cb72
BLAKE2b-256 37da58e5d3ac9b0419b2c7b5a42840668f37b6b50df4ac7f5914fc9d49bc6660

See more details on using hashes here.

File details

Details for the file django_simditor2-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_simditor2-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 123244a061c24d418ce92fd3cfb9ce864be63a407cea196972cc84ece14b0a8f
MD5 ed4e215840190be6f28218fe0f5c28a0
BLAKE2b-256 00bfe254e0c1d2587cf0a5c4895cc051156021a4e949c6d4d7fdb9f157d3b67e

See more details on using hashes here.

Supported by

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