博客中KindEditor配置[通俗易懂]

博客中KindEditor配置[通俗易懂]1.下载 KindEditor2.放在static/js下3.在admin.py中配置文件:4.在static/js/kindeditor下配置config.js文件首先在kindedito官网文档中,找到代码:根据代码提示编辑:5.编辑图片和文件上传代码:#-*-coding:utf-8-*-fromdjango.httpimp…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

1.下载 KindEditor博客中KindEditor配置[通俗易懂]

2.放在static/js下

博客中KindEditor配置[通俗易懂]

3.在admin.py中配置文件:

博客中KindEditor配置[通俗易懂]

4.在static/js/kindeditor下配置config.js文件

首先在kindedito官网文档中,找到代码:

博客中KindEditor配置[通俗易懂]

根据代码提示编辑:

博客中KindEditor配置[通俗易懂]

博客中KindEditor配置[通俗易懂]

5.编辑图片和文件上传代码:

博客中KindEditor配置[通俗易懂]
博客中KindEditor配置[通俗易懂]

# -*- coding: utf-8 -*-
from django.http import HttpResponse
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
import os
import uuid
import json
import datetime as dt


@csrf_exempt
def upload_image(request, dir_name):
    ##################
    #  kindeditor图片上传返回数据格式说明:
    # {"error": 1, "message": "出错信息"}
    # {"error": 0, "url": "图片地址"}
    ##################
    result = {"error": 1, "message": "上传出错"}
    files = request.FILES.get("imgFile", None)
    if files:
        result =image_upload(files, dir_name)
    return HttpResponse(json.dumps(result), content_type="application/json")


def upload_generation_dir(dir_name):
    """
    目录创建
    :param dir_name:
    :return:
    """
    today = dt.datetime.today()
    dir_name = dir_name + '/%d/%d/' %(today.year,today.month)
    if not os.path.exists(settings.MEDIA_ROOT + dir_name):
        os.makedirs(settings.MEDIA_ROOT + dir_name)
    return dir_name


def image_upload(files, dir_name):
    """
    图片上传
    :param files:
    :param dir_name:
    :return:
    """
    allow_suffix =['jpg', 'png', 'jpeg', 'gif', 'bmp'] #允许上传文件类型
    file_suffix = files.name.split(".")[-1]
    if file_suffix not in allow_suffix:
        return {"error": 1, "message": "图片格式不正确"}
    relative_path_file = upload_generation_dir(dir_name)
    path=os.path.join(settings.MEDIA_ROOT, relative_path_file)
    if not os.path.exists(path): #如果目录不存在创建目录
        os.makedirs(path)
    file_name=str(uuid.uuid1())+"."+file_suffix
    path_file=os.path.join(path, file_name)
    file_url = settings.MEDIA_URL + relative_path_file + file_name
    open(path_file, 'wb').write(files.file.read()) # 保存图片
    return {"error": 0, "url": file_url}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182698.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • vue 中 input事件「建议收藏」

    vue 中 input事件「建议收藏」vue中input事件input事件的使用<div:id=”inputId”:class=”[‘textarea_content_right’]”:contenteditable=”true”@input=”changeText($event)”v-text=”currentValue”></div>​data(){return…

    2022年6月11日
    418
  • 进程分析工具 process_grep查看进程

    进程分析工具 process_grep查看进程当进程卡住不动或者死锁时,pstack可以把当前进程的代码栈打出来,方便我们排查。用法非常简单,后面直接加进程号即可。如果是多线程的,则会打印每个线程的堆栈信息。manpstack可查看帮助[root@localhost~]#pstack7383Thread8(Thread0x7fcc0429c700(LWP7384)):#00x00007fcc0d322a82inpthread_cond_timedwait@@GLIBC_2.3.2()from/lib64/.

    2022年9月14日
    0
  • Python open函数详解「建议收藏」

    Python open函数详解「建议收藏」演示环境,操作系统:Win1021H2(64bit);Python解释器:3.8.10。open是Python的一个内置函数,一般用于本地文件的读写操作。用法如下。my_file=open(file,mode,buffering,encoding,errors,newline,closefd,opener)#打开文件…#读写操作。省略my_file.colse()#释放文件open函数必须搭配.close()方法使用,先用open打开文件,然后进行读写操

    2022年5月20日
    45
  • 微信支付接口文档

    微信支付接口文档

    2021年10月12日
    51
  • Spring Batch示例教程

    Spring Batch示例教程SpringBatch示例教程欢迎使用SpringBatch示例。SpringBatch是一个用于执行批处理作业的弹簧框架模块。我们可以使用spring批处理来处理一系列作业。目录[隐藏]1SpringBatch示例 1.1SpringBatch示例 1.2Spring批处理示例目录结构 1.3SpringBatchMaven依赖项 …

    2022年5月28日
    102
  • maven常用打包命令

    maven常用打包命令maven常用打包命令1、mvncompile编译,将Java源程序编译成class字节码文件。2、mvntest测试,并生成测试报告3、mvnclean将以前编译得到的旧的class字节码文件删除4、mvnpakage打包,动态web工程打war包,Java工程打jar包。5、mvninstall将项目生成jar包放在仓库中,以便别的模块调用6、mvncleaninstall-Dmaven.test.skip=true打成jar包,并且抛弃测

    2022年6月3日
    114

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号