Django Admin 中使用 wangEditor 富文本编辑器
Project description
django_wang_echo_editor 富文本编辑器
- 封装了wangEditor富文本编辑器,支持本地图片上传和OSS存储 wangEditor官方文档:https://www.wangeditor.com/
- 基于python3.10,django4.2版本进行测试
- 仅仅为了自己开发测试使用,存在不可遇见的bug
安装
- 安装django_wang_echo_editor
pip install django_wang_echo_editor
- 在settings文件INSTALLED_APPS中添加“wang_editor”
INSTALLED_APPS = [
...
wang_editor,
]
- 在settings中添加静态文件路径
STATIC_URL = 'static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- 在urls中添加静态文件对应的路由
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
...
path('wang_editor/', include('wang_editor.urls')),
]
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
使用
1.在模型models中使用
from django.db import models
from wang_editor.fields import WangEditorField
class Article(models.Model):
content = WangEditorField()
2.使用本地上传图片
- 在settings中添加媒体文件路径
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
- 在urls中添加媒体文件路径
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3.config配置
WANG_EDITOR_CONFIG = {
'upload': '', # 本地服务器上传路径,以MEDIA_URL为基础
'storage_backend': '', # 使用OSS存储
'custom_css': [], # 自定义css
'custom_js': [], # 自定义js
'origin_js': '', # wangEditor的js文件,
'toolbar_config': {}, # 工具栏配置
'editor_config': {} # 编辑器配置
}
- toolbar_config和editor_config的配置参考wangEditor官方文档
https://www.wangeditor.com/
- 如果配置了storage_backend,则upload配置无效
4.支持图片和视频上传到OSS之类的存储 在配置文件中添加storage_backend配置,值为存储后端的类路径,如:
WANG_EDITOR_CONFIG = {
'storage_backend': 'wang_editor.backends.aliyun.AliyunOSSBackend'
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_wang_echo_editor-0.1.3.tar.gz.
File metadata
- Download URL: django_wang_echo_editor-0.1.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
862801c88be898c2b4e4a65df1d4086f1f4b7d697d06eea6799a009090794eb2
|
|
| MD5 |
b6a743d25ee55f1faa224d4de092bf8c
|
|
| BLAKE2b-256 |
71aabec626d42be449910e235f28cc0180d77459a31272ca3ccdfee1e60335d2
|
File details
Details for the file django_wang_echo_editor-0.1.3-py3-none-any.whl.
File metadata
- Download URL: django_wang_echo_editor-0.1.3-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
818873168134826de96ffd4eb9eb3718d8c70565e8b6fbdc7c840f71d4829db9
|
|
| MD5 |
6074630d23f636d0f790c299eb3cb52f
|
|
| BLAKE2b-256 |
f43f9756bd25d728df41fcb8c408d6eaa9bcbc4c6e95b10c96329dde8b2a187f
|