使用WTForms填充textarea字段

问题描述

据我了解,如果要填充文本区域,请将文本放置在文本区域标签之间。但是我正在使用WTForms。如何从视图或模板中预填充表单?

表格

class ModuleSectionForm(FlaskForm):
    title = StringField('Section Title',validators=[Datarequired()])
    description = TextAreaField('Description',validators=[Datarequired()])
    submit = SubmitField('Add Section')

查看

@modules.route('/update_section/<name>/<title>',methods=['GET','POST'])
def update_section(name,title):
    form = ModuleSectionForm()
    module = Module.objects(title=name).first()
    section = None
    for sect in module.sections:
        if sect.title == title:
            section = sect
    #if form.validate_on_submit():
        #save data 
    return render_template('modules/update_section.html',section=section,form=form) 

模板

<form method="post" action="{{ url_for('modules.update_section',name=name) }}">
    {{ form.hidden_tag() }}
    <div class="form-group">
        {{ form.title.label(class="form-control-label") }}
        {{ form.title(class="form-control",value=section.title) }}
    </div>
    <div class="form-group">
        {{ form.description.label(class="form-control-label") }}
        {{ form.description(class="form-control",default=section.description) }}
    </div>
    <div class="form-group">
        {{ form.submit(class="btn btn-secondary shadow") }}
    </div>
</form>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)