Skip to main content

Django Textarea Widget Integrated Vditor with Customizable Configuration

Project description

dj_vditor

Django-vditor 是基于 vditor v3.8.0 的一个 django Markdown 文本编辑插件应用。

Django-mdeditor 的灵感参考自伟大的项目 django-ckeditor.

Installation

### 默认安装只需Django
pip install dj-vditor-widget

### 安装oss上传插件
pip install dj-vditor-widget[oss]

### 安装tos上传插件
pip install dj-vditor-widget[tos]

### 安装所有插件
pip install dj-vditor-widget[all]

Quick Start

  1. Add to INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    'dj_vditor',
]
  1. Add URL route in urls.py:
# 当然你也可以自定义url和view, 只要跟配置中的upload.url一致即可
from dj_vditor.views import vditor_images_upload_view

urlpatterns = [
   ...
    path('upload/', vditor_images_upload_view, name='vditor_upload'),
]
  1. Use in Model:
from dj_vditor.models import VditorTextField

class Article(models.Model):
    content = VditorTextField()
  1. Configure settings:
# settings.py
# 如果你需要使用阿里云的OSS上传, 请设置以下配置
# DJ_IMAGE_UPLOADER_OSS_CONFIG = {
#     "ACCESS_KEY": getenv("ALIYUN_ACCESS_KEY_ID"),
#     "SECRET_KEY": getenv("ALIYUN_ACCESS_KEY_SECRET"),
#     "ENDPOINT": getenv("OSS_ENDPOINT"),
#     "BUCKET_NAME": getenv("OSS_BUCKET_NAME"),
# }

# 如果要使用火山引擎的TOS上传, 请设置以下配置
DJ_IMAGE_UPLOADER_TOS_CONFIG = {
    "ACCESS_KEY": getenv("VOLCENGINE_ACCESS_KEY"),
    "SECRET_KEY": getenv("VOLCENGINE_SECRET_KEY"),
    "ENDPOINT": getenv("VOLCENGINE_ENDPOINT"),
    "BUCKET_NAME": getenv("VOLCENGINE_BUCKET_NAME"),
    "REGION": getenv("VOLCENGINE_REGION"),
}
# 这是默认配置, 如果不需要修改的话, 可以不设置, 直接使用默认配置
DEFAULT_CONFIG = {
    "width": "100%",
    "height": 720,
    "cache": {"enable": False},
    "mode": "sv",
    "debugger": "false",
    "icon": "ant",
    "outline": "",
    "counter": {
        "enable": True,
    },
    "lang": "zh_CN",
    "toolbar": [
        "emoji",
        "headings",
        "bold",
        "italic",
        "strike",
        "link",
        "|",
        "list",
        "ordered-list",
        "check",
        "outdent",
        "indent",
        "|",
        "quote",
        "line",
        "code",
        "inline-code",
        "insert-after",
        "table",
        "|",
        "upload",
        "fullscreen",
        "export",
        "|",
        "outline",
    ],
    "upload": {
        "storage": "local",
        "local_path": "admin",
        "url": "/upload/",  # 上传接口地址
        "max": 5 * 1024 * 1024,  # 5MB
        "accept": "image/png,image/jpeg,image/gif,image/webp",  # 允许类型
        "fieldName": "file[]",
        "multiple": True,
    },
}

# 如果要覆盖的话, 可以在settings.py中设置VDITOR_CONFIGS, 这样就不会使用默认配置了
VDITOR_CONFIGS = {
    "upload": {"local_path": "my_custom_path", "storage": "tos"},
    "height": 500,
}

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

dj_vditor_widget-0.3.3.tar.gz (4.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_vditor_widget-0.3.3-py3-none-any.whl (4.2 MB view details)

Uploaded Python 3

File details

Details for the file dj_vditor_widget-0.3.3.tar.gz.

File metadata

  • Download URL: dj_vditor_widget-0.3.3.tar.gz
  • Upload date:
  • Size: 4.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for dj_vditor_widget-0.3.3.tar.gz
Algorithm Hash digest
SHA256 6c6b8f7da1d15f1a3e7e9a27f03383644fb311f1af503ef32891dc680fa78f27
MD5 42ab547ceefdaf3c4a8b5b342431f941
BLAKE2b-256 1c7a1da43c4e647ed49716971ede83b79fe27a6569eec93565d883e014b8f843

See more details on using hashes here.

File details

Details for the file dj_vditor_widget-0.3.3-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_vditor_widget-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 760f6e2bc7fc67c18aa3cf87ff2c25b5f4d83fde8b0506760d55d66a13933db0
MD5 d2d1633aa4917f2ce253f516b4474064
BLAKE2b-256 e7c596fd6b870806145c0fb840e0cc8066244a7f59f58cc477d66641b299a87d

See more details on using hashes here.

Supported by

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