如何在不更改变量名称的情况下设置 WTForm 字段的名称属性?

How can I set the name attribute of a WTForm Field, without changing the variable name?

我正在尝试设置这些 WTForm 字段的名称,而不必更改变量本身的名称。任何帮助表示赞赏。

class AddProblemForm(Form):
    problem_point_value_data = [[10, 20, 30], [40, 50, 60], [70, 80, 90, 100], [120, 140, 160, 180, 200]]
    problemName = StringField('problemName',_name="problemName", validators=[validators.DataRequired(), validators.Length(min=2, max=64)])
    problem_description = PageDownField('problemDescription', validators=[validators.DataRequired(), validators.Length(min=10, max=512)])
    flag = StringField('flag', validators=[validators.DataRequired(), validators.Length(min=5, max=64)])
    problem_difficulty = SelectField('problemDifficulty', choices=[(x, x) for x in range(4)], coerce=int)
    problem_points = SelectField('problemPoints', choices=[(x, diff) for x,diff in zip(range(len(app.config['POINTS'])), app.config['POINTS'])], coerce=int)
    problem_category = SelectField('problemCategory', choices=[(x, cat) for cat,x in zip(app.config['CATEGORIES'], range(len(app.config['CATEGORIES'])))], coerce=int)
    problem_solution = TextAreaField('problemSolution', validators=[validators.DataRequired()])

这里的问题(是的,双关语绝对是故意的!)是您用 problemName = StringField() 定义了一个字段。这个字段除了 'problemName' 外别无其他名称。

文本标签与 Moses 评论的不同,您的 HTML 可以显示任何内容。