Skip to main content

一个简单的tinymce富文本编辑器的django第三方包!

Project description

bayketinymce

安装配置

安装

pip install bayketinymce-django

配置

1、在django项目配置文件settings文件中的INSTALLED_APPS注册app,并设置图片上传保存路径

INSTALLED_APPS = [
    ...
    'tinymce',
]

MEDIA_URL = 'media/'
MEDIA_ROOT = BASE_DIR / 'media'

2、上传图片配置

在django项目的根urls.py中引入以下url

from django.urls import path, include

from django.conf import settings
from django.conf.urls.static import static
from tinymce.views import TinyMCEImageUpload

urlpatterns = [
    path('admin/', admin.site.urls),
    # 富文本编辑器上传图片url
    path("tinymce/upload-image/", TinyMCEImageUpload.as_view(), name="tinymce-upload-image")
]

# 开发环境下配置静态文件URL
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

快速使用

在models中使用

from tinymce.fields import TinyMCEField

class Article(models.Model):
    content = TinyMCEField()

在forms表单中中使用

# forms.py
from django import forms
from tinymce.forms import TinyMCEField
from tinymce.widgets import TinyMCEWidget

class TinyMCEForm(forms.Form):

    content = TinyMCEField(label="详情")

    or

    content = forms.CharField(widget=TinyMCEWidget(
            attrs={"class": 'input'}, tinymce_config={'menubar': False}
        )
    )

本项目所有的富文本编辑器相关均依赖 TinyMCEWidget 小部件,可以通过定制修改其参数tinymce_config的值(字典)来设置对应的富文本配置,具体配置项请参考tinymce官方配置文档,不支持配置js的方法及函数,仅支持 配置其值为字符串或数组及键值对对象的配置项!

修改默认富文本编辑器配置

在项目的settings.py中引入 TINYMCE_CONFIG 配置,该值是一个字典!

TINYMCE_CONFIG = {
    # 是否开启富文本编辑器菜单,默认关闭,这里的配置会覆盖掉默认配置
    'menubar': False,
}

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

bayketinymce-django-0.0.1.tar.gz (766.9 kB view details)

Uploaded Source

Built Distribution

bayketinymce_django-0.0.1-py3-none-any.whl (824.6 kB view details)

Uploaded Python 3

File details

Details for the file bayketinymce-django-0.0.1.tar.gz.

File metadata

  • Download URL: bayketinymce-django-0.0.1.tar.gz
  • Upload date:
  • Size: 766.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.0

File hashes

Hashes for bayketinymce-django-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c75ad93c6b798c4acfae1b80162583095fe8ebd1780ef9fc8478710d6147a7da
MD5 ebc90e942ad115bf0b013ca4e6bbed90
BLAKE2b-256 6f4a1b0e953ad556602a33137ec52f84a252f496e445a34884f7188bf803d1ef

See more details on using hashes here.

File details

Details for the file bayketinymce_django-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bayketinymce_django-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80abdc0e7d8a9869fcad5cc0b959c7e3027deb0d1004faa6ed3c4e107b59338c
MD5 b56c3646fa4ffca52e6411ced4e4c880
BLAKE2b-256 6120f964ef5577f8bd6b9435ca7c877613186de7c9a8be65e2f853e21c0532c1

See more details on using hashes here.

Supported by

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