富文本编辑器HTMLField与 mdeditor

27 篇文章 1 订阅
14 篇文章 0 订阅

1、引入HTMLField之前,需要安装:

pip install Django-mdeditor
pip install Django-tinymce

2、在models.py中导入模块:

from django.db import models
from mdeditor.fields import MDTextField
from tinymce.models import HTMLField

# Create your models here.
class Bid(models.Model):
    name = models.CharField('项目名称', max_length=100, default='--')#项目名称
    district = models.CharField('地区', max_length=100, default='--')#地区
    type = models.CharField('种类', max_length=100, default='--')#种类
    dom = models.CharField('域名', max_length=100, default='--')  # 种类
    purl = models.URLField(max_length=100, verbose_name='链接网址', default='--')#连接网址
    tenderee = models.CharField('招标单位', max_length=100, default='--')#招标人
    tenderer = models.CharField('投标单位', max_length=100, default='--')#投标单位
    address = models.CharField('施工地址', max_length=100, default='--')#施工地址
    docnmb = models.CharField('公告文件号', max_length=100, default='--')#公告文件号
    startaffich = models.DateField('公告发布日期', null=True)#公告发布日期
    endaffich = models.DateField('公告截止日期', null=True)  # 公告截止日期
    startRegistration = models.DateTimeField('报名开始日期', null=True)  # 报名开始日期
    endRegistration= models.DateTimeField('报名结束日期', null=True)  # 报名结束日期
    crawltime = models.DateTimeField('爬取时间', auto_now_add=True)  # 爬取时间日期
    bloomnb = models.CharField('哈希值', max_length=200)  # 哈希值
    md =MDTextField('MD富文本编辑器',null = True)
    content = HTMLField('HTML富文本编辑器',null = True)

就可以引用HTMLField了。

、在setting中进行相关的配置
(1)在app中进行注册(INSTALLED_APPS)

INSTALLED_APPS = [

    # 'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'BuildingPlat',
    'mdeditor',
    'tinymce'
]


(2)在settings.py添加富文本编辑器配置信息,设置富文本编辑器的宽高

MDEDITOR_CONFIGS = {
    'default': {
        'width': '90% ',  # Custom edit box width
        'heigth': 500,  # Custom edit box height
        'toolbar': ["undo", "redo", "|",
                    "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
                    "h1", "h2", "h3", "h5", "h6", "|",
                    "list-ul", "list-ol", "hr", "|",
                    "link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime"
                                                                                                           "emoji",
                    "html-entities", "pagebreak", "goto-line", "|",
                    "help", "info",
                    "||", "preview", "watch", "fullscreen"],  # custom edit box toolbar
        'upload_image_formats': ["jpg", "jpeg", "gif", "png", "bmp", "webp"],  # image upload format type
        'image_folder': 'editor',  # image save the folder name
        'theme': 'default',  # edit box theme, dark / default
        'preview_theme': 'default',  # Preview area theme, dark / default
        'editor_theme': 'default',  # edit area theme, pastel-on-dark / default
        'toolbar_autofixed': True,  # Whether the toolbar capitals
        'search_replace': True,  # Whether to open the search for replacement
        'emoji': True,  # whether to open the expression function
        'tex': True,  # whether to open the tex chart function
        'flow_chart': True,  # whether to open the flow chart function
        'sequence': True,  # Whether to open the sequence diagram function
        'watch': True,  # Live preview
        'lineWrapping': False,  # lineWrapping
        'lineNumbers': False  # lineNumbers
    }


TINYMCE_DEFAULT_CONFIG = {
    'theme': 'advanced',
    'width': 600,
    'height': 400,
}

(3)在项目总的urls.py中添加tinymce的路由信息

from django.conf.urls import url, include
from django.contrib import admin
from BuildingPlat import views
from django.conf.urls.static import static
from django.conf import settings
from django.urls import  re_path

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$',views.home),
    url(r'mdeditor/', include('mdeditor.urls')),#MD富文本编辑器
    re_path(r'^tinymce/', include('tinymce.urls')),#HTML富文本编辑器
]

DJANGO后台显示结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值