在admin或者adminx后台中使用富文本编辑器

一.建立模型:(安装django-tinymce==2.6.0)

                from django.db import models
from tinymce.models import HTMLField
# Create your models here.
class GoodTest(models.Model):
status_choices = (
(0, '下线'),
(1, '上线')
)
status = models.SmallIntegerField(default=1, choices=status_choices, verbose_name='状态')
# 富文本类型:带有格式的文本
detail = HTMLField(blank=True, verbose_name='商品详情')

二.在settings.py中完成配置

                INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01.apps.App01Config',
'tinymce',
] TINYMCE_DEFAULT_CONFIG = {
'theme': 'advanced',
'width': 600,
'height': 400,
}

三.路由分发



           url('tinymce/', include('tinymce.urls')),  # 富文本编辑器

四. admin.py中完成注册

                from app01.models import GoodTest

                # Register your models here.
admin.site.register(GoodTest)
05-11 15:11