Company recently to do a content management system, need to integrate a Baidu editor in the background, inspected a bit, are recommended Baidu editor.
Baidu Editor in the HTML embedded very easy, give the sample copied to their own HTML can, I am not the front end, but according to my test, should be to introduce jquery.
After embedding, Baidu Editor basic can be used, the common text format can be saved to the database, the need for direct removal, the format is still in, it seems that my cause has been completed more than half.
It is important to note that if the document displayed to the foreground is escaped, such as <p> is shown as <p>, then you need to find out how to close teplate escape, and the tornado I use only needs to be written on the HTML document:
{% Autoescape None%}
Things must not be so simple, the uploading of images is a problem.
General Web page display of pictures, to try to put on their own server or picture station, because most of the site's pictures will block other site references, and then their website will open the skylight. Our company for this project, temporarily use seven cattle escrow.
That is to say, the backstage manager uses the Baidu editor to upload the picture I have to find a way to Daoteng seven cattle up.
Baidu to the code does not contain Python, a buddy did a Django plugin, I also do not understand the source. So I went online to check.
Baidu Editor's Dialog/image folder has a image.html, is click on the image after uploading the page elements, which is actually a form. The seven-ox SDK can generate tokens as long as the token submission form is up.qiniu.com. The method provided on the Internet is basically the same, and I really do not understand JS, do not know where to add tokens, and where to change the location of the image submission.
So far, I also feel that this is the best way to simply not need the server to participate in the case (just generate a token only), just a manager's computer with seven of cattle server interaction. And so I've been stuck here for a long time.
Have to spit groove, Baidu's documents do not really do. I feel that the answer I want is on this page, but I really can't understand what this is saying, is it let me dynamically generate a Config.json?
I didn't see the following words until the next day:
。。。
Well, I can't find it again. The general meaning is as follows:
1. The new upload-related interface is no longer differentiated, but uses a unified request interface
2. When the editor is loaded, the request will be sent to the link in config.js and the required parameters will be displayed before the image upload is normal.
3. The load priority of the image loading configuration is back-up > The configuration >config.json in the Baidu editor. Yes, the Config.json configuration is for reference only.
I just realized that I do not have to take care of those PHP documents, and do not have to tube Config.json, Baidu editor all the requests to the server can, as long as the server side, the basic can do.
First change the ServerURL to your own server, look at the document, the image you want parameters:
{ "ImageUrl": "Http://localhost/ueditor/php/controller.php?action=uploadimage", "ImagePath": "/ueditor/php/", "Imagefieldname": "Upfile", "Imagemaxsize": 2048, "Imageallowfiles": [". png", ". jpg", ". jpeg", ". gif", ". bmp"] "Other configuration items ...": "Other configuration values ..."}
Because all requests are currently pointing to the same link, they carry parameters, such as when requesting a server configuration:? action=config
When the server determines that the parameter is config, return the above parameters. But still not good, I carefully observed that the parameters in the Config.json is not the case.
"Imageactionname": "Uploadimage",/* Perform the action name of the upload picture * /"Imagefieldname": "Upfile",/* submitted picture form name */ " Imagemaxsize ": 2048000,/* Upload size limit, Unit B * /" imageallowfiles ": [". png ",". jpg ",". jpeg ",". gif ",". bmp "],/* Upload picture format display */< c5/> "imagecompressenable": true,/* whether to compress the picture, the default is true * /"Imagecompressborder": 1600,/* picture compression longest edge limit */ " Imageinsertalign ":" None ",/* Insert Picture Floating way * /" Imageurlprefix ":" ",/* Picture access Path prefix */
When these parameters are passed in, the configuration is found to be correct. The parameters in the Baidu documentation are the old versions of the parameters.
The comment of the above parameter is basically clear, because is the server handles the uploading picture the matter, I will return the complete path, the picture filename is also the server definition, therefore does not need to set.
When uploading a picture, the GET request carries the parameter uploadimage (the setting above), while the parameter of the POST request is upfile (the setting above).
In addition to the file itself, there are original_name,file_type, I guess Original_name is Baidu editor used to distinguish the return of the image link.
Image after the server processing, uploaded to seven cattle, you need to return the link address to Baidu browser.
Take a closer look at PHP's function action_upload.php for uploading files, and find the following comments:
* Array (* "state" = "" ", //upload status, must be returned" SUCCESS "*" url "=" ""/"*" and "// address returned * " title "=" //New file name * "original" + "",/ /original file name * "type" = "" " //File type * " size "=" ", //File size * )
According to the sample painting scoop can. One of the state of the Lake Success,url is uploaded seven cattle after the address, title can fill in one, with the front end of the words, you can let the background manager to customize the title of the picture. Original and type are Baidu editor sent up, send back can, size optional.
Just go back and get it done.
Baidu Editor's python background