如何将所见即所得编辑器与 django flatpages 集成?我尝试了 django-ckeditor,但没有很好地描述它。有人试过吗?
问问题
3076 次
3 回答
11
我只是通过 admin.py 中的以下代码将 django-ckeditor 连接到 flatpages 应用程序:
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from django.db import models
from cked.widgets import CKEditorWidget
class FlatPageCustom(FlatPageAdmin):
formfield_overrides = {
models.TextField: {'widget': CKEditorWidget}
}
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageCustom)
有用!
于 2013-09-01T15:14:36.170 回答
0
from django.db.models import Field
from django.forms import Textarea
from settings import MEDIA_URL
class WidgetWYSIWYG(Textarea):
def __init__(self, *args, **kwargs):
super(WidgetWYSIWYG, self).__init__(attrs={'class': 'wysiwygEditor vLargeTextField'}, *args, **kwargs)
class Media:
js = (
MEDIA_URL+'common/tiny_mce/tiny_mce.js',
MEDIA_URL+'common/filebrowser/js/TinyMCEAdmin.js',
)
class WYSIWYGField(Field):
def get_internal_type(self):
return "TextField"
def formfield(self, **kwargs):
defaults = {'widget': WidgetWYSIWYG}
defaults.update(kwargs)
return super(WYSIWYGField, self).formfield(**defaults)
在文件 admin.py
from django.contrib import admin
from wysiwyg import WidgetWYSIWYG
from django.db import models
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatPageAdmin as FlatPageAdminOld
class FlatPageAdmin(FlatPageAdminOld):
formfield_overrides = {
models.TextField: {'widget': WidgetWYSIWYG},
}
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
于 2013-02-13T23:18:02.687 回答
0
我会试试这个应用程序。它使用 Tiny MCE。
于 2013-07-06T13:49:34.217 回答