WTForms-如何预填充textarea字段? [英] WTForms-How to prepopulate a textarea field?

查看:212
本文介绍了WTForms-如何预填充textarea字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用某些方法填充textareafield 在模板中是这样的.

Hi I have been trying to pepopulate a textareafield using something like this in the template.

{{form.content(value="please type content")}}

这在字段为文本字段时有效,主要是因为html 接受<input type="text">的值 但对于textarea来说这是行不通的... 有人可以帮我吗?

This works when the field is textfield primarily because the html accepts value for <input type="text"> but the same does not work for textarea... Can someone please help me with this?

推荐答案

对于textarea小部件,您可以在字段构造函数中使用default参数设置默认内容.

For textarea widgets, you set the default content with the default argument in your field constructors.

class YourForm(Form):
    your_text_area = TextAreaField("TextArea", default="please add content")

然后在渲染时:

{{form.content()}}

WTForms将呈现默认文本.我还找不到在渲染时为文本区域指定默认文本的方法.

WTForms will render the default text. I have not been able to find a way to specify default text for the text area at render time.

这篇关于WTForms-如何预填充textarea字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆