Deprecated! Now that source code of kindeditor does not update for a long time and the editor sometimes on worked as expected, this repo will no longer update. Recommend to use django-ckeditor or vue+djangorestframework instead.
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/
- Django 2.0+
- Python 3.6+
- 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)
)
# 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)
-
Clone the repo to local
git clone https://github.com/waketzheng/django-kindeditor
-
Create a virtual environment and install required packages
pipenv install --dev
-
Activate it
pipenv shell
-
Migrate and compile translation file
./manage.py migrate ./manage.py compilemessages
-
Runserver
./manage.py runserver
-
View the url and you will see the demo at webbrowser.
-
Test Coverage
coverage run ./manage.py test
-
Test multiple django versions
tox
-
Show code quality
coverage xml python-codacy-coverage -r coverage.xml