flask 富文本编辑器(flask 22)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了flask 富文本编辑器(flask 22)相关的知识,希望对你有一定的参考价值。

参考技术A

from flask_ckeditor import CKEditor, upload_success, upload_fail

app = Flask( name )
ckeditor=CKEditor(app)
app.config[\'CKEDITOR_SERVE_LOCAL\'] = True
app.config[\'CKEDITOR_FILE_UPLOADER\'] = \'upload_for_ckeditor\'
app.config[\'CKEDITOR_PKG_TYPE\'] = \'standard\' #basic,full
app.config[\'CKEDITOR_LANGUAGE\']=\'zh-cn\'

@app.route(\'/ckeditor\', methods=[\'GET\', \'POST\'])
def integrate_ckeditor():
form = RichTextForm()
if form.validate_on_submit():
title = form.title.data
body = form.body.data
flash(\'Your post is published!\')
return render_template(\'post.html\', title=title, body=body)
return render_template(\'ckeditor.html\', form=form)
@app.route(\'/upload-ck\', methods=[\'POST\'])
def upload_for_ckeditor():
f = request.files.get(\'upload\')
if not allowed_file(f.filename):
return upload_fail(\'Image only!\')
f.save(os.path.join(app.config[\'UPLOAD_PATH\'], f.filename))
url = url_for(\'get_file\', filename=f.filename)
return upload_success(url, f.filename)

from flask_ckeditor import CKEditorField
class RichTextForm(FlaskForm):
title = StringField(\'Title\', validators=[DataRequired(), Length(1, 50)])
body = CKEditorField(\'Body\', validators=[DataRequired()])
submit = SubmitField(\'Publish\')

% extends \'base.html\' %
% from \'macros.html\' import form_field %

% block content %
<h2>Integrate <a href="https://ckeditor.com">CKEditor</a>
with <a href="https://github.com/greyli/flask-ckeditor">Flask-CKEditor</a>
</h2>
<form method="post">
form.csrf_token
form_field(form.title)
form_field(form.body)
form.submit
</form>
% endblock %

% block scripts %
super()
ckeditor.load()
ckeditor.config(name=\'body\')
% endblock %

% extends \'base.html\' %

% block title % title % endblock %

% block head %
super()

ckeditor.load_code_theme()
% endblock %

% block content %
<h1> title </h1>
<p> body|safe </p>
% endblock %

flask 扩展包

1、pipenv install python-dotenv  (管理项目环境变量);

2、pipenv install watchdog --dev(监测文件变动,一般开发时使用);

3、pipenv install flask-wtf (表单插件);

4、pipenv install flask-ckeditor(富文本编辑器);

5、pipenv install flask-sqlalchemy(数据库管理);

6、pipenv install flask-mail(发送邮件);

7、pipenv install bootstrap-flask(bootstrap前端css组件);

8、pipenv install flask-moment(时间和日期处理函数组件);

9、pipenv install flask-debugtoolbar(调试工具);

10、pipenv install flask-login(用户认证组件);

11、

 

以上是关于flask 富文本编辑器(flask 22)的主要内容,如果未能解决你的问题,请参考以下文章

Flask 项目集成富文本编辑器 CKeditor

使用Flask-CKEditor在Flask项目中集成富文本编辑器

Python学习笔记:6.3.4 富文本编辑器

小白都能看得懂的教程 一本教你如何在前端实现富文本编辑器

flask 扩展包

为 Flask 编写一个百度编辑器的插件