python - 如何将 bootstrap wysiwyg 添加到 flask 中?

标签 python bootstrap-wysiwyg

我想使用bootstrap wysiwyg在我的 Flask 网站中。 我找到了这个项目flask-wysiwyg并遵循了作者的建议,但它不起作用。

我想知道:

  • 出了什么问题?
  • 我该如何自己解决这个问题?

这是代码:

表单.py

from .wysiwyg import WysiwygField

class PostForm(Form):
    article_title = StringField(u'title', validators=[Required(), Length(1, 64)])
    body = WysiwygField(u"txteditor", validators=[Required()])
    submit = SubmitField(u'submit')

查看.py

# views.py
from .forms import PostForm
@main.route('/post', methods=['GET', 'POST'])
@login_required
def post():
    title = u'edit'
    form = PostForm()
    if  form.validate_on_submit():
        posts = Post(article_title=form.article_title.data,
                     body=form.body.data,
                     author=current_user._get_current_object())
        db.session.add(posts)
        flash(u'commit')
        return redirect(url_for('.doc'))
    return render_template('post-rich-text-edit.html', title=title, form=form)

post-rich-text-edit.html

{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block head %}
{{ super() }}
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='prettify.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='font-awesome.css') }}">


    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
{% endblock %}

{% block page_content %}
<div class="page-header">
    <div class="row">
        <div class="col-md-12">
            <form method=post action="/">
            {{ form.article_title }}
                {{ form.hidden_tag() }}
                {{ form.body.label }}
                <div id="editor">
                {{ form.body(size=20) }}

                </div>
            {{ form.submit }}
            </form>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
{{ super() }}
    <script  type="text/javascript" src="{{ url_for('static', filename='bootstrap-wysiwyg.js') }}"></script>
    <script  type="text/javascript" src="{{ url_for('static', filename='jquery.hotkeys.js') }}"></script>
    <script  type="text/javascript" src="{{ url_for('static', filename='prettify.js') }}"></script>
{% endblock %}

最佳答案

目前还不清楚您面临的问题是什么。但是,您有一个观点,flask-wysiwyg 的文档包可能会产生误导。

要使用 WysiwygField,请将 forms.py 中的 import 语句 更改为:

from flask_wysiwyg.wysiwyg import WysiwygField

关于python - 如何将 bootstrap wysiwyg 添加到 flask 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35798386/

相关文章:

python - SimpleCookie 泛型类型

Python unpickle 一个对象里面有一个类实例

python - 用 Python 3.6 连接 MySQL

python - 如何删除 tkinter Frame 中的内容

javascript - 如何使用 Bootstrap 验证来验证所见即所得编辑器

javascript - 如何计算所见即所得编辑器javascript中的单词数?

javascript - bootstrap-wysiwyg 编辑器未显示

python - 合并到一个文件时文件数据会成倍增加,为什么?