我想在Flask
网站中使用bootstrap wysiwyg。
我找到了这个项目flask-wysiwyg并遵循了作者的建议,但它不起作用。
我想知道:
以下是代码:
form.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')
view.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)
富后-文本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 %}
答案 0 :(得分:2)
目前尚不清楚您面临的问题是什么。但是,您必须指出https://regex101.com/r/gY6sB8/1包的文档可能会产生误导。
要使用WysiwygField
,请将import statement
中的forms.py
更改为:
from flask_wysiwyg.wysiwyg import WysiwygField
答案 1 :(得分:0)
将scripts block
中的最后3行移至head block
答案 2 :(得分:0)
将 <table id = "whad"> </table>
添加到WysiwygField
forms.py
并添加到from flask_wysiwyg.wysiwyg import WysiwygField
block scripts
post-rich-text-edit.html