[英]Embedding tinyMCE in django flatpage
I'm using django-tinymce . 我正在使用django-tinymce 。 I'd like to know how to embed it in a flatpage in admin panel.
我想知道如何将其嵌入管理面板的平面页面中。
From the project's readme: 从项目的自述文件:
Add tinymce to INSTALLED_APPS in settings.py for your project: 在settings.py中为项目添加tinymce到INSTALLED_APPS:
INSTALLED_APPS = (
...
'tinymce',
)
Add tinymce.urls to urls.py for your project: 将tinymce.urls添加到您的项目的urls.py:
urlpatterns = patterns('',
...
(r'^tinymce/', include('tinymce.urls')),
)
My flatpage url : 我的平面网址:
url(r'^pages/', include('django.contrib.flatpages.urls')),
you need to override the widget for the content field. 您需要覆盖内容字段的小部件。 To do this:
去做这个:
FlatpageForm
ModelForm as PageForm
FlatpageForm
ModelForm扩展为PageForm
FlatPageAdmin
to use the new PageForm
FlatPageAdmin
以使用新的PageForm
code example: 代码示例:
from django.contrib.flatpages.admin import FlatpageForm, FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
## OOPS this is a custom widget that works for initializing
## tinymce instances on stacked and tabular inlines
## for flatpages, just use the tinymce packaged one.
#from content.widgets import TinyMCE
from tinymce.widgets import TinyMCE
class PageForm(FlatpageForm):
class Meta:
model = FlatPage
widgets = {
'content' : TinyMCE(attrs={'cols': 100, 'rows': 15}),
}
class PageAdmin(FlatPageAdmin):
"""
Page Admin
"""
form = PageForm
then unregister the old flatpage admin and reregister the new one 然后取消注册旧的平面管理员并重新注册新的平面管理员
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, PageAdmin)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.