suneditor icon indicating copy to clipboard operation
suneditor copied to clipboard

How can I use SunEditor with Flask?

Open Calabashmc opened this issue 2 years ago • 3 comments

I've been trying wysiwyg editors for my Flask project. I really like yours but can't figure out how to get data in and out of it using Flask-WTF

I am currently using Trix-editor and it just pairs with an input field. I then just read data from that input field So I can load like this: my_text_area_feild.data = data_from_my_database

and get the text and images out to store in database like this: my_db_model_col = my_text_area_feild.data

How can I do this with SunEditor? I can't figure it out!

I am very new to programming.

Calabashmc avatar Mar 18 '22 09:03 Calabashmc

I am also using Python3/Flask and I am using Javascript in combination with Flask templates and routes to save and load (html) data on a server side database, not Flask forms. E.g. to save, a use Fetch API with a Flask POST route. (Not sure this was very helpful...)

MRB60 avatar Mar 21 '22 14:03 MRB60

Thanks for the response. Can you provide a code example?

Calabashmc avatar Mar 22 '22 00:03 Calabashmc

I am using Vue framework but it can look something like this to open up the editor from javascript. Could be done at the bottom of the page in tags: this.suneditor = SUNEDITOR.create((document.getElementById('suneditor') || 'suneditor'), editorconfig); this.suneditor.setContents(HTMLeditorcontent);

Html: <textarea id="suneditor"></textarea>

For the 'POST' upload to Flask via javascript: let contents = this.suneditor.getContents(); let jcontents = JSON.stringify(contents); this.update({'contents':jcontents});

where update() is a Vue method ('js function') using 'Fetch API' to upload as a 'POST' request to Flask. It might be possible to have a Flask form and load the form from javascript prior to submit but I think will shall take that over PM instead if that is the path you want to take. Still suggest you look in to Fetch API (not sure it is possible with IE) or similar.

MRB60 avatar Mar 22 '22 06:03 MRB60