与大多数文章不同,我没有尝试将 tinyMCE 集成到管理页面中。
我正在构建一个包含多个博客的站点,并且我想将 tinyMCE 集成到用户应该输入他的文章的文本区域中。上面提到的 textarea 不在管理控制台中。
我阅读了文档并逐行按照步骤操作。我所做的唯一更改是使用 STATIC_ROOT 而不是 MEDIA_ROOT。
我的Setting.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tinymce',
'pages',
'blog',
'django_summernote',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
TEMPLATE_CONTEXT_PROCESSORS = {
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.request',
}
STATIC_ROOT = 'F:/Projects/trebuchet/site/blog_test/'
STATIC_URL = '/static/'
############ TINY MCE ################
TINYMCE_JS_URL = os.path.join(STATIC_ROOT, "static/tiny_mce/tiny_mce.js")
TINYMCE_JS_ROOT = os.path.join(STATIC_ROOT, "static/tiny_mce")
TINYMCE_JS_URL = os.path.join(STATIC_ROOT,'static/tiny_mce/tiny_mce_src.js')
TINYMCE_DEFAULT_CONFIG = {
"relative_urls": "false",
"theme": "advanced",
"theme_advanced_buttons1": "formatselect,bold,italic,underline,link,unlink,bullist,undo,code,image",
"theme_advanced_buttons2": "",
"theme_advanced_buttons3": "",
"plugins": "paste",
"height": "550px",
"width": "750px",
}
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True
BlogForm.py
class addBlog(forms.ModelForm):
body = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
class Meta:
model = ArticleModel
fields = ['title', 'body', 'category']
widgets = {'body': TinyMCE(attrs={'cols': 80, 'rows': 30})}
class Media:
js = ( 'static/tiny_mce/tiny_mce.js', 'static/tiny_mce/blog_textareas.js')
models.py
class Category(models.Model):
name = models.CharField(max_length=30)
description = models.TextField(max_length=100)
def __unicode__(self):
return self.name
class ArticleModel(models.Model):
title = models.CharField(max_length=200)
body = models.TextField()
datetime = models.DateTimeField()
username = models.CharField(max_length=50)
category = models.CharField(max_length=30)
tags = JSONField()
def __unicode__(self):
return self.title
现在我尝试了很多解决方案,但没有成功。