简体   繁体   中英

django-summernote image upload

I recently implemented django-summernote with my forms, which works well for text. However, I struggle to get exactly how image upload works. Does anyone have some input on how it is done?

Problem

When choosing an image from file with Summernote, the Insert Image button is deactivated (works fine for image links). I did not write a custom 'upload_to' function, but as I get it, this is already done in django-summernote.

Details

  1. Installed django-summernote according to documentation.
  2. Added summernote to urls and in INSTALLED_APPS
  3. Added summernote to my form field

    directions = forms.CharField( widget=SummernoteInplaceWidget(attrs={'maxlength':'4000'}), required=False, )

  4. Also added some config in SUMMERNOTE_CONFIG (settings.py)

     SUMMERNOTE_CONFIG = { 'iframe': True, 'airMode': True, 'width': '100%', 'height': '300', 'toolbar': [ # ['style', ['style']], ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']], # ['fontname', ['fontname']], ['fontsize', ['fontsize']], # ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ['height', ['height']], ['table', ['table']], ['insert', ['link', 'picture', 'video', 'hr']], ['view', ['fullscreen', 'codeview']], ['help', ['help']], ], } 

Do I also have to write my own backend for attachments (images)? STATIC_URL and MEDIA_URL is defined in my settings.py, if that matters for this issue.

Update November 29th 2014:

When choosing an image, the following error is given in the console: "undefined is not a function", which is related to

imageInput.fileupload();

The "Insert Image" button is disabled.

As my project is in developing mode, I have DEBUG=True in my settings.

My urls look like:

urlpatterns += patterns('',
  url(r'^summernote/', include('django_summernote.urls')),
  ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

and Media_root and Media_url are set to:

MEDIA_ROOT = path.join(path.dirname(__file__), 'media',)
MEDIA_URL = '/media/'

I use picture uploads outside django-summernote with these settings.

Feels like I am missing something, but can´t see what.

Thanks in advance.

django-summernote shipped with backend support for image uploading out of box. So you don't have to write your own backend for it. MEDIA_ROOT or MEDIA_URL settings may have wrong value for uploading - permission problem or not valid path.

Run django project with runserver and please check the browser console(inspect) and python console after trying to upload an image.

And also refer Need a minimal Django file upload example for handling files on django project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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