|
1 | 1 | # Editor.js for Django |
2 | | -Django plugin for using Editor.js |
| 2 | + |
| 3 | +Django plugin for using [Editor.js](https://editorjs.io/) |
| 4 | + |
| 5 | +> This plugin works fine with JSONField in Django >= 3.1 |
| 6 | +
|
| 7 | +## Installation |
| 8 | + |
| 9 | +```bash |
| 10 | +pip install django-editorjs |
| 11 | +``` |
| 12 | + |
| 13 | +Add django_editorjs to INSTALLED_APPS in settings.py for your project: |
| 14 | +```python |
| 15 | +# settings.py |
| 16 | +INSTALLED_APPS = [ |
| 17 | + ... |
| 18 | + 'django_editorjs', |
| 19 | +] |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +Add code in your model |
| 25 | +```python |
| 26 | +# models.py |
| 27 | +from django.db import models |
| 28 | +from django_editorjs import EditorJsJSONField, EditorJsTextField # import |
| 29 | + |
| 30 | + |
| 31 | +class Post(models.Model): |
| 32 | + body_default = models.TextField() |
| 33 | + body_editorjs = EditorJsJSONField() # Django >= 3.1 |
| 34 | + body_editorjs_text = EditorJsTextField() # Django <= 3.0 |
| 35 | + |
| 36 | +``` |
| 37 | + |
| 38 | +Or add custom Editor.js plugins and configs ([List plugins](https://github.com/editor-js/awesome-editorjs)) |
| 39 | + |
| 40 | +```python |
| 41 | +# models.py |
| 42 | +from django.db import models |
| 43 | +from django_editorjs import EditorJsJSONField, EditorJsTextField # import |
| 44 | + |
| 45 | + |
| 46 | +class Post(models.Model): |
| 47 | + body_custom = EditorJsJSONField( |
| 48 | + plugins=[ |
| 49 | + "@editorjs/image", |
| 50 | + "@editorjs/header", |
| 51 | + "editorjs-github-gist-plugin", |
| 52 | + "@editorjs/code@2.6.0", # version allowed :) |
| 53 | + "@editorjs/list@latest", |
| 54 | + "@editorjs/inline-code", |
| 55 | + "@editorjs/table", |
| 56 | + ], |
| 57 | + tools={ |
| 58 | + "Image": { |
| 59 | + "config": { |
| 60 | + "endpoints": { |
| 61 | + # Your custom backend file uploader endpoint |
| 62 | + "byFile": "/editorjs/image_upload/" |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + }, |
| 67 | + null=True, |
| 68 | + blank=True |
| 69 | + ) |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +If you want to upload images to the editor then add django_editorjs.urls to urls.py for your project: |
| 74 | +```python |
| 75 | +# urls.py |
| 76 | +from django.contrib import admin |
| 77 | +from django.urls import path, include |
| 78 | +from django.conf import settings |
| 79 | +from django.conf.urls.static import static |
| 80 | + |
| 81 | +urlpatterns = [ |
| 82 | + path('admin/', admin.site.urls), |
| 83 | + path('editorjs/', include('django_editorjs.urls')), |
| 84 | +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |
| 85 | +``` |
| 86 | + |
| 87 | +See an example of how you can work with the plugin [here](https://github.com/2ik/django-editorjs/blob/main/example) |
| 88 | + |
| 89 | + |
| 90 | +## Support and updates |
| 91 | + |
| 92 | +Use github issues https://github.com/2ik/django-editorjs/issues |
0 commit comments