froala / django-froala-editor

Package to integrate Froala WYSIWYG HTML rich text editor with Django.
https://froala.com/wysiwyg-editor
283 stars 72 forks source link

Upload image error for lacking of csrf token #52

Closed j4tmr closed 5 years ago

j4tmr commented 6 years ago

When i use FroalaField to upload a image from local, the error occurs.

akki744 commented 5 years ago

@jhd4tmr This issue can be easily resolved by passing the csrf token in the form where you are actually using the froala field to fix the null error. Use below code snippet for reference :- <form method="POST" enctype="multipart/form-data"> {% csrf_token %} {{ editor }}
</form> Thanks.

StevenMapes commented 4 years ago

This error can still happen when the editor is within Django Admin

jainankit102 commented 3 years ago

There is the option requestHeaders that allows you to send headers along with the requests made by the editor. This includes all requests that it makes: image/file upload, save, image manager load, etc. https://www.froala.com/wysiwyg-editor/docs/options?&_ga=2.146425521.484195098.1627981207-1122276901.1627981207#requestHeaders

codeparl commented 1 year ago

Thanks @jainankit102 , your solution worked for me very well.

ivan-de-jager248 commented 1 year ago

I found the potential problem (in my case at least).

One of the options included for the editor in django-froala-editor by default is "imageUploadParams": {"csrfmiddlewaretoken": getCookie("csrftoken")}

As soon as you add your own options for imageUploadParams in settings.py or in the FroalaField(options), the default csrfmiddlewaretoken is overwritten and not appended, even though the docs say it's appends to existing options.

I found the problem in froala_editor/widgets.py(48):

class FroalaEditor(widgets.Textarea):
    #---
    def get_options(self):
        #---
        # This overwrites any default options with dictionary values
        options.update(self.options.items())