pip install flask-ckeditor
from flask_ckeditor import CKEditor
ckeditor = CKEditor(app)
@app.route('/fwb', methods=['GET', 'POST'])
def fwb():
if request.method == 'POST':
print(request.form.get('ckeditor'))
return request.form.get('ckeditor')
return render_template('fuwenben.html')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form method="post">
{{ ckeditor.create() }}
<input type="submit">
</form>
{{ ckeditor.load() }}
{{ ckeditor.config() }} <!-- 这时不用设置name参数 -->
</body>
</html>
另外一种方式是用像wtf一样使用
from flask_wtf import FlaskForm
from flask_ckeditor import CKEditorField
from wtforms import StringField, SubmitField
# 定义类
class PostForm(FlaskForm):
title = StringField('Title')
body = CKEditorField('Body')
submit = SubmitField('Submit')
#定义路由处理
@app.route('/fwbwtf', methods=['GET', 'POST'])
def fwb_wtf():
form=PostForm()
if request.method == 'POST':
print(form.body.data)
return form.body.data
return render_template('fuwenbenwft.html',form=form)
{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}
{% block content %}
{{ super() }}
<form method="post">
{{ form.title.label }}{{ form.title() }}
{{ form.body.label }}{{ form.body() }}
{{ form.submit() }}
</form>
{{ ckeditor.load() }}
{{ ckeditor.config(name='body') }}
{% endblock %}