wtforms

WTForms getting the errors

*爱你&永不变心* 提交于 2019-12-03 01:57:12
Currently in WTForms to access errors you have to loop through field errors like so: for error in form.username.errors: print error Since I'm building a rest application which uses no form views, I'm forced to check through all form fields in order to find where the error lies. Is there a way I could do something like: for fieldName, errorMessage in form.errors: ...do something The actual form object has an errors attribute that contains the field names and their errors in a dictionary. So you could do: for fieldName, errorMessages in form.errors.items(): for err in errorMessages: # do

Disabled field is considered for validation in WTForms and Flask

拜拜、爱过 提交于 2019-12-02 19:33:45
I have some fields in page disabled as for example:(using jinja2 templating system) <html> <body> <form action="" method=POST> {{ form.name(disabled=True) }} {{ form.title }} -- submit button -- </form> </body> </html> Field is disabled in the form as expected. In my views.py: On doing validate_on_submit() on form submit, it fails with validation error on 'name' field which is disabled. I was hoping that validation ignores disabled field. Is it the right behaviour? If so, can you please let know how to handle such a case? Updated: class TeamForm(wtf.Form): name = wtf.TextField("Team Name",

Flask-SQLAlchemy: How to conditionally insert or update a row

强颜欢笑 提交于 2019-12-02 17:37:30
My application uses a combination of Flask, Flask-SQLAlchemy, Flask-WTF and Jinja2. In its current incarnation, I have a settings table. The table will only have one record with one field. Initially the table contains zero records. What I want to achieve is: Given that no entries exist in db, then show empty form ready for user input Given that an entry exist, show the entry, and if the user changes the value, then update the rec in db. Here is my code: models.py class Provider(db.Model): id = db.Column(db.Integer, primary_key = True) rssfeed = db.Column(db.String(120), unique = True) def _

Checking uniqueness contraint during form validation in App Engine

拜拜、爱过 提交于 2019-12-02 17:05:25
问题 I am using Flask and WTforms in App Engine, trying to implement uniqueness contraint on one of the field. The question is big, please be patient and I have been stuck here from many hours, need some help from you people. Started learning App Engine, Flask and WTForms a month ago. Thanks in advance. Application has model 'Team' as shown below: class Team(db.Model): name = db.StringProperty(required=True) -- some other fields here -- Requirement: Name of the team has to be unique. I have

Flask. sqlalchemy.exc.InterfaceError: <app.models.Menu object at 0x7f287026dd10>

馋奶兔 提交于 2019-12-02 14:08:37
问题 I am using QuerySelectField in my forms.py and when submitting it I get the following error: InterfaceError: (InterfaceError) Error binding parameter 8 - probably unsupported type. u'INSERT INTO menu (title, title_eng, alias, menu_type, ordering, check_out_time, access, published, parent_id, image, content, content_eng, metades, metakey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' (u'\u0423\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438

Checking uniqueness contraint during form validation in App Engine

ε祈祈猫儿з 提交于 2019-12-02 09:46:18
I am using Flask and WTforms in App Engine, trying to implement uniqueness contraint on one of the field. The question is big, please be patient and I have been stuck here from many hours, need some help from you people. Started learning App Engine, Flask and WTForms a month ago. Thanks in advance. Application has model 'Team' as shown below: class Team(db.Model): name = db.StringProperty(required=True) -- some other fields here -- Requirement: Name of the team has to be unique. I have followed the links http://www.codigomanso.com/en/2010/09/solved-anadir-claves-unicas-en-google-app-engine-en

TypeError: __init__() got an unexpected keyword argument 'password'

安稳与你 提交于 2019-12-02 08:46:27
问题 I can't find out what's the cause of this error TypeError: __init__() takes at most 2 arguments (3 given) which is pointing to @user_blueprint.route('/login', methods=['GET', 'POST']) def login(): if g.user.is_authenticated: flash("You are already Logged in", 'warning') return redirect(url_for('members')) error = "" form = LoginForm() if request.method == 'POST': if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is not None and bcrypt.check

WTForms: IntegerField skips coercion on a string value

南楼画角 提交于 2019-12-02 08:08:43
问题 I have a Form instance with a single IntegerField . The IntegerField renders to HTML as an <input> with type="text" and data gets POSTed back from an HTML form as a text string. However the form will not validate if the posted data has a string value for the IntegerField (passed in via a dict in the data parameter). Here's a toy example: from wtforms import validators, Form, IntegerField class TestForm(Form): num = IntegerField('How Many?', [validators.NumberRange(min=1, max=100)]) test_form1

Flask WTForms always give false on validate_on_submit()

随声附和 提交于 2019-12-02 06:30:50
问题 I have created a signup form using wtforms. I am using FormField in it so that I don't have to repeat some of the elements of the form again. But whenever I click on the Submit button it always give me false on validate_on_submit method invocation. Not getting why is this happening. My form.py is as follows: class ProfileInfoForm(Form): firstname = TextField('firstname', validators= [validators.Required("Please enter First name.")]) lastname = TextField('lastname', validators= [validators

Flask. sqlalchemy.exc.InterfaceError: <app.models.Menu object at 0x7f287026dd10>

强颜欢笑 提交于 2019-12-02 05:12:02
I am using QuerySelectField in my forms.py and when submitting it I get the following error: InterfaceError: (InterfaceError) Error binding parameter 8 - probably unsupported type. u'INSERT INTO menu (title, title_eng, alias, menu_type, ordering, check_out_time, access, published, parent_id, image, content, content_eng, metades, metakey) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' (u'\u0423\u0441\u043b\u043e\u0432\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f', u'terms of connecting', u'terms', u'simple', 4, '2014-01-23 00:00:00.000000', u'public', u'1',