wtforms

Unique validator in WTForms with SQLAlchemy models

我们两清 提交于 2019-12-18 10:54:45
问题 I defined some WTForms forms in an application that uses SQLALchemy to manage database operations. For example, a form for managing Categories: class CategoryForm(Form): name = TextField(u'name', [validators.Required()]) And here's the corresponding SQLAlchemy model: class Category(Base): __tablename__= 'category' id = Column(Integer, primary_key=True) name = Column(Unicode(255)) def __repr__(self): return '<Category %i>'% self.id def __unicode__(self): return self.name I would like to add a

Flask WTForms: Difference between DataRequired and InputRequired

南楼画角 提交于 2019-12-18 03:54:35
问题 What is difference between DataRequired and InputRequired in wtforms.valiadators I have some fields in my signup form : username password password_repeat submit Should these fields use the DataRequired or InputRequired validator? 回答1: Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code: Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired

Flask WTForms: Difference between DataRequired and InputRequired

假装没事ソ 提交于 2019-12-18 03:54:35
问题 What is difference between DataRequired and InputRequired in wtforms.valiadators I have some fields in my signup form : username password password_repeat submit Should these fields use the DataRequired or InputRequired validator? 回答1: Short Answer Unless you have a good reason you should use InputRequired Why? Lets look at some notes from the docs/code: Note there is a distinction between this and DataRequired in that InputRequired looks that form-input data was provided, and DataRequired

Using Flask-WTForms, how do I style my form section of the html?

狂风中的少年 提交于 2019-12-18 03:38:29
问题 I read through Flask-WTF extremely simplified wiki, and couldn't understand much about what I can do with it. I am under the impression that the <form> section of the html now can only look like <form method="post"> {{ form.hidden_tag() }} {{ form.name }} <input type="submit"> </form> But I really want to style my using materialized such as: <div class="row"> <div class="input-field col s6"> <i class="material-icons prefix">account_circle</i> <input value="FN" id="first_name" type="text"

How to use WTForms in Ajax validation?

空扰寡人 提交于 2019-12-17 22:35:57
问题 I accustomed of using WTForms by means of Flask-WTF in my flask application. Doing server side validation is trivial. But how do I leverage this server validation to become a field level, ajax, client side validation? So, when user tab to another input fields, my application can directly goes on validating it and give validation warning/info/error. I haven't found a resource in the internet yet 回答1: A possible solution is as follows: On the client side you attach a handler to the blur event

How to use a WTForms FieldList of FormFields?

假装没事ソ 提交于 2019-12-17 10:47:00
问题 I'm building a website using Flask in which I use WTForms. In a Form I now want to use a FieldList of FormFields as follows: class LocationForm(Form): location_id = StringField('location_id') city = StringField('city') class CompanyForm(Form): company_name = StringField('company_name') locations = FieldList(FormField(LocationForm)) so to give people the ability to enter a company with two locations (dynamic adding of locations comes later) I do this on the front side: <form action="" method=

How to bind a field in __init__ function of a form

我的梦境 提交于 2019-12-13 17:24:50
问题 class Example_Form(Form): field_1 = TextAreaField() field_2 = TextAreaField() def __init__(self, type, **kwargs): super(Example_Form, self).__init__(**kwargs) if type == 'type_1': self.field_3 = TextAreaField() In some scenarios I need to dynamically add fields into the form. The field_3 added to example form turns out to be a UnboundField. I tried to bind field_3 to form in __init__ function, but it won't work. field_3 = TextAreaField() field_3.bind(self, 'field_3') How to bind field_3 to

How to specify rows and columns of a <textarea > tag using wtforms

a 夏天 提交于 2019-12-13 11:53:28
问题 Constructing a wtforms' TextAreaField is something like this: content = wtf.TextAreaField('Content', id="content-area", validators=[validators.Required()]) How can I specify the number of rows and columns associated with this textarea? 回答1: You are not supposed to do it in the place where you declare the widget. You have do it in the template. For eg: {{form.content(rows='50',cols='100')}} Need to ensure the rows and cols are specified as a string. 回答2: Much simpler; use render_kw argument

How do you store the request.form to db through wtforms or error in sqlalchemy update?

假装没事ソ 提交于 2019-12-13 04:23:20
问题 This is following on from this question: SQLalchemy/wtforms update issue - 400 bad request I have a flask framework Issue When I submit the form the flash message comes up saying prediction added although when I query the db nothing has changed?? Can anyone spot where I'm going wrong? What am I trying to achieve Users are able to view their predictions making changes to current predictions. If there are no new predictions then they can submit new predictions. views # Predictor - User makes

AppEngine NDB property validations

本小妞迷上赌 提交于 2019-12-13 03:07:19
问题 I wonder what the best approach is for validating NDB entity properties likes: a date must be in the future a grade (integer property) must be between 1 and 10 a reference to another entity must have certain property values (e.g. book.category.active must be True) I'm also using WTForms to validate submitted requests, but I want to enforce validations also on a lower level like the datastore entities itself. So basically what I'm looking for is to call a validate on a datastore entity to see