免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2546 | 回复: 0
打印 上一主题 下一主题

在 Django 中配置 FCKEditor(一) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-25 08:05 |只看该作者 |倒序浏览

                                1.在项目下创建 util目录.并新建 __init__.py 文件.内容留空即可
2.在util目录下创建 cache.py 内容如下
               
               
                # -*- coding:utf-8 -*-
class CacheContainer(object):
   pass
3.在util目录下新建cachemiddleware.py 内容如下
from util.cache import CacheContainer as Cache
class CacheMiddleware(object):
   
    def process_request(self, request):
       Cache.user_agent = request.META.get('HTTP_USER_AGENT',"")
4.在util目录下新建editor.py 内容如下
#!/usr/bin/env python
from django.forms.widgets import Widget
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
import fckeditor
from util.cache import CacheContainer as Cache
class FCKEditor(Widget):
    def __init__(self, attrs=None):
        if attrs is not None:
            self.attrs = attrs.copy()
        else:
            self.attrs = {}
        self.__widget = fckeditor.FCKeditor("FCKeditor1")
        self.__widget.sAgent = Cache.user_agent or ""
        super(FCKEditor, self).__init__(attrs)
        self.setAtters(self.attrs)
    def setAtters(self, attrs):
        if attrs is None:
            return
        if 'basepath' in attrs:
            self.__widget.BasePath = attrs['basepath']
        if 'width' in attrs:
            self.__widget.Width = attrs['width']
        if 'height' in attrs:
            self.__widget.Height = attrs['height']
        if 'toolbar' in attrs:
            self.__widget.ToolbarSet = attrs['toolbar']
    def render(self, name, value, attrs=None):
        if value is None: value = ''
        value = force_unicode(value)
        self.__widget.InstanceName = name
        self.__widget.Value = value
        self.setAtters(attrs)
        final_attrs = self.build_attrs(attrs, name=name)
        return mark_safe(self.__widget.CreateHtml())
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8660/showart_1910300.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP