flaskform pass a variable (WTForms)

前端 未结 2 1169
一个人的身影
一个人的身影 2021-01-28 18:24

I want to pass a str to be used as the prompt for a form. I thought it would be simple but it is proving to be difficult.

Here is my code:

class PostFo         


        
2条回答
  •  梦毁少年i
    2021-01-28 18:54

    So, I still don't have an answer to the question, but I did manage to come up with a solution.

    class PostForm(FlaskForm):
        post = TextAreaField(_l('This no longer matters'), validators=[DataRequired()])
        submit = SubmitField(_l('Submit'))
    

    And then in the routes

    from wtforms.fields.core import Label
    form = PostForm()
    form.post.label = Label("post", 'Real question goes here')}
    

    The explanation for this is that TextAreaField creates a label attribute on post that is accessible and changable, but it needs to be formated correctly as a Label object from wtforms.fields.core. (Simply reassigning it as a string did not work). The representation of this object is:

    
    

    And it is of type

    
    

提交回复
热议问题