Django框架学习笔记(29.kindeditor插件使用)

在官网下载好Kindeditor,粘贴到静态文件夹。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div style="width: 500px; margin: 0 auto;">
    <textarea id="content"></textarea>
</div>

<script src="/static/jquery-1.12.4.js"></script>
<script src="/static/kindeditor/kindeditor-all.js"></script>
<script>
    $(function(){
        KindEditor.create('#content',{
            uploadJson:'/upload_img/'
        });
    })
</script>
</body>
</html>

初始化参数详细见:http://kindeditor.net/docs/option.html

这里写出几个重要的参数:

resizeType

2或1或0,2时可以拖动改变宽度和高度,1时只能改变高度,0时不能拖动。

  • 数据类型: Int
  • 默认值: 2

uploadJson

指定上传文件的服务器端程序。

  • 数据类型: String
  • 默认值: basePath + ‘php/upload_json.php’

allowImageUpload

true时显示图片上传按钮。

  • 数据类型: Boolean
  • 默认值: true

allowImageRemote

true时显示网络图片标签,false时不显示。

  • 数据类型: Boolean
  • 默认值: true

autoHeightMode

值为true,并引入autoheight.js插件时自动调整高度。

  • 数据类型: Boolean
  • 默认值: false

allowFileManager

true时显示浏览远程服务器按钮。(下边有一个写好的示例)

  • 数据类型: Boolean
  • 默认值: false

filePostName

指定上传文件form名称。(可以用request.FILES.get('name'))

  • 数据类型: String
  • 默认值: imgFile


用filemanager时候在views.py中加入:

import os
import time
import json
def file_manager(request):
    dic = {}
    root_path = 'C:/Users/Administrator/PycharmProjects/Django/static/'
    static_root_path = '/static/'
    request_path = request.GET.get('path')
    if request_path:
        abs_current_dir_path = os.path.join(root_path, request_path)
        move_up_dir_path = os.path.dirname(request_path.rstrip('/'))
        dic['moveup_dir_path'] = move_up_dir_path + '/' if move_up_dir_path else move_up_dir_path

    else:
        abs_current_dir_path = root_path
        dic['moveup_dir_path'] = ''

    dic['current_dir_path'] = request_path
    dic['current_url'] = os.path.join(static_root_path, request_path)

    file_list = []
    for item in os.listdir(abs_current_dir_path):
        abs_item_path = os.path.join(abs_current_dir_path, item)
        a, exts = os.path.splitext(item)
        is_dir = os.path.isdir(abs_item_path)
        if is_dir:
            temp = {
                'is_dir': True,
                'has_file': True,
                'filesize': 0,
                'dir_path': '',
                'is_photo': False,
                'filetype': '',
                'filename': item,
                'datetime': time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getctime(abs_item_path)))
            }
        else:
            temp = {
                'is_dir': False,
                'has_file': False,
                'filesize': os.stat(abs_item_path).st_size,
                'dir_path': '',
                'is_photo': True if exts.lower() in ['.jpg', '.png', '.jpeg'] else False,
                'filetype': exts.lower().strip('.'),
                'filename': item,
                'datetime': time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(os.path.getctime(abs_item_path)))
            }

        file_list.append(temp)
    dic['file_list'] = file_list
    return HttpResponse(json.dumps(dic))


简单的效果图:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值