Closed j4tmr closed 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.
This error can still happen when the editor is within Django Admin
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
Thanks @jainankit102 , your solution worked for me very well.
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())
When i use FroalaField to upload a image from local, the error occurs.