django-kindeditor

Django admin KindEditor integration.


License
MIT
Install
pip install django-kindeditor==0.3.0

Documentation

django-kindeditor

image image image image image image image

This repo is to make it easy to use KindEditor as a RichTextEditor when using django.

You can visit this site to see the editor result: http://kindeditor.org/

Chinese[δΈ­ζ–‡η‰ˆ]

Requires

  • Django 2.0+
  • Python 3.6+

Usage

  • Install
pip install django-kindeditor
  • Add kindeditor to INSTALL_APPS in settings, and define static, media
INSTALLED_APPS = [
    ...
    'kindeditor',
]
...

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')  # your static files path
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')  # your media files path
  • Insert "kindeditor/" path and static, media paths to urlpatterns in urls.py
from django.conf import settings

if settings.DEBUG:
    # static and media
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    urlpatterns.extend(
        staticfiles_urlpatterns()
        + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    )
urlpatterns = [
    ...
    path("kindeditor/", include("kindeditor.urls")),
]

if settings.DEBUG:
    # static and media
    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    urlpatterns.extend(
        staticfiles_urlpatterns()
        + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    )

Example

# models.py
from kindeditor import RichTextField

class Article(models.Model):
    title = models.CharField(max_length=80)
    content = RichTextField()

# settings.py
KINDEDITOR_UPLOAD_PERMISSION = 'admin'

# admin.py
from django.contrib import admin
from kindeditor import EditorAdmin
from .models import Article
admin.site.register(Article, EditorAdmin)

Demo

  1. Clone the repo to local

    git clone https://github.com/waketzheng/django-kindeditor
  2. Create a virtual environment and install required packages

    pipenv install --dev
  3. Activate it

    pipenv shell
  4. Migrate and compile translation file

    ./manage.py migrate
    ./manage.py compilemessages
  5. Runserver

    ./manage.py runserver
  6. View the url and you will see the demo at webbrowser.

    http://127.0.0.1:8000

Development

  1. Test Coverage

    coverage run ./manage.py test
  2. Test multiple django versions

    tox
  3. Show code quality

    coverage xml
    python-codacy-coverage -r coverage.xml