我如何動態地創建幾個帶有不同問題的表單域,但答案相同?WTForms創建可變數量的字段
from wtforms import Form, RadioField
from wtforms.validators import Required
class VariableForm(Form):
def __init__(formdata=None, obj=None, prefix='', **kwargs):
super(VariableForm, self).__init__(formdata, obj, prefix, **kwargs)
questions = kwargs['questions']
// How to to dynamically create three questions formatted as below?
question = RadioField(
# question ?,
[Required()],
choices = [('yes', 'Yes'), ('no', 'No')],
)
questions = ("Do you like peas?", "Do you like tea?", "Are you nice?")
form = VariableForm(questions = questions)
我不清楚這個解決方案是否與我的問題有關我在我的Post模型中有關係叫做標籤......當我調用PostForm生成標籤時,查詢會顯示查詢結果如何運行查詢並將結果作爲逗號描述字符串發送到郵政標籤字段?這是我的[發佈的問題](http://stackoverflow.com/questions/23251470/how-to-send-query-results-to-a-wtform-field)。 – jwogrady 2014-04-23 23:21:21
通過這種方式,它不能解決問題,你不能像form.py那樣分開形式文件,然後是'a = Form(params)',定義類內部的方法不被認爲是好的做法? https://stackoverflow.com/questions/2583620/dynamically-create-class-attributes – TomSawyer 2017-10-09 09:09:58