[英]Trumbowyg: Django server can detect file upload but not image URL input

I'm using Trumbowyg, a WYSIWYG JavaScript editor which has a feature of rendering images from URLs pasted in. It also has an upload plugin which enables uploading local images and custom server side handling.


My python/django function upload_image() can successfully detect the uploaded image - however when I use the URL image input, my python function cannot detect it. Trumbowyg simply renders the image without going through my python backend.

我的python / django函數upload_image()可以成功檢測上傳的圖像 - 但是當我使用URL圖像輸入時,我的python函數無法檢測到它。 Trumbowyg只是渲染圖像而不通過我的python后端。

Here's my code:


    btnsDef: {
        // Create a new dropdown
        image: {
            dropdown: ['insertImage', 'upload'],
            ico: 'insertImage'
    // Redefine the button pane
    btns: [
        ['strong', 'em', 'del'],
        ['image'], // Our fresh created dropdown
    plugins: {
        // Add imagur parameters to upload plugin for demo purposes
        upload: {
            serverPath: '/upload_image/',
            fileFieldName: 'content_image',
            urlPropertyName: 'url'
def upload_image(request):
    print('Success') #only prints when I use the upload input, not the URL input

Why can in detect the uploaded image but not the URL input?


1 个解决方案



As already pointed, Trumbowyg doesn't send the URL to backend if the user uploads the image using a URL.


But if you really want to host the images on your own server, there's a way you can do that.


When the user submits the form, you'll receive the content of the textarea in your backend. You can then read the content and look for <img src="..."> tag.


At that point, you can check if the src value doesn't start with your S3 bucket hostname, you can download that image using urllib or requests library, save it to your bucket and replace the src value.


Since the submitted data will be in HTML format, check out the excellent Beautiful Soup. It will make parsing HTML easy.

由於提交的數據將采用HTML格式,因此請查看優秀的Beautiful Soup。它將使解析HTML變得容易。



粤ICP备14056181号  © 2014-2021