问题描述
我正在编写代码来获取数据,因为用户在 ckeditor 中为我的拼写检查项目键入(或复制粘贴到编辑器),我需要在每次更改时在编辑器中获取数据,所以我创建了一个变量 editorData,它将保持更改后的值。但是由于我是网络编程的新手,我无法使用 python Flask 将这些数据发送到服务器,我的代码如下所示:
<!DOCTYPE html>
<html>
<head>
<Meta charset="utf-8">
<title>CKEditor 5 – Classic editor</title>
<script src="https://cdn.ckeditor.com/ckeditor5/25.0.0/classic/ckeditor.js"></script>
</head>
<body>
<h1>Classic editor</h1>
<div id="editor" method ="POST" ></div>
<script>
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( editor => {
editor.model.document.on( 'change:data',() => {
editorData = editor.getData();
console.log( 'The data has changed!' )
} );
} )
.catch( error => {
console.error( error );
} );
</script>
</body>
</html>
Python 烧瓶代码
from flask import Flask,render_template,request
from flask_ckeditor import CKEditor
app = Flask(__name__)
@app.route('/',methods=['GET'])
def new_post():
print('hello')
if request.method == ' POST':
data = editorData
print(data)
return render_template('test-page.html')
if __name__ == "__main__":
app.run(debug=True)
请帮助我如何在每次编辑器发生变化时将创建的 javascript 变量发送到 Flask 服务器。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)