简体   繁体   English

如何使用Django后端在CKEDITOR中上传图片?

[英]How to upload image in CKEDITOR with a Django backend?

I have done proper research of many image plugins which upload images to server using php scripts.I just want to know a proper way to upload images to a django-based server. 我已经对许多使用php脚本将图像上传到服务器的图像插件进行了适当的研究,我只想知道一种将图像上传到基于django的服务器的正确方法。

Here's I think what a approach should be - 我认为这应该是一种方法-

On clicking a toolbar button,a dialog will be opened.UI elements of the dialog will include a form with a file type,two fields for height and width and a button (upload to server).On adding a image file and fields and clicking upload button,ajax call will be sent (am i right here? or form submit should handle it.) to the server where a particular view will handle saving image to a specified folder. 单击工具栏按钮时,将打开一个对话框。对话框的UI元素将包括一个带有文件类型的表单,两个用于高度和宽度的字段以及一个按钮(上传到服务器)。在添加图像文件和字段并单击上传按钮,ajax调用将被发送到服务器(服务器是在这里吗?还是通过表单提交来处理)。服务器将在其中特定视图处理将图像保存到指定文件夹的情况。

On success server will return the full path of the image and dialog will insert in the editor. 成功后,服务器将返回图像的完整路径,对话框将插入编辑器。

Sorry if my question is very naive but I just wanted to know if my assumptions are right before starting off. 抱歉,如果我的问题很幼稚,但我只想在开始之前就知道我的假设是否正确。

Thanks 谢谢

There is a Django package 有一个Django包

https://github.com/django-ckeditor/django-ckeditor

This comes with a demo app. 它带有一个演示应用程序。 I would advise to look into that, and see how it works. 我建议调查一下,看看它是如何工作的。

Basically you will have to configure the media url and there is a setting for ckeditor where to upload the media. 基本上,您将必须配置媒体URL,并且ckeditor有一个将媒体上传到何处的设置。 Ckeditor will handle the image upload for you. Ckeditor将为您处理图像上传。

Uploaded content will be show in an overview page, where you will have the option "use image in text" 上传的内容将显示在概述页面中,您可以在其中选择“在文本中使用图像”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM