Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

python - Getting SelectField from wtf forms flask

I have used the answers from similar questions on here to create this however, when getting the fields I get an SQL insert error IntegrityError: (sqlite3.IntegrityError) NOT NULL constraint failed: orders.pickupTime

this is the checkout.html page

<form class="form" action="" method="post" novalidate>
                                    {{ form.hidden_tag() }}
                            <div class="single-widget">
                                <h2>Payments</h2>
                                <div class="content">
                                    <div class="checkbox">
                                        <label class="checkbox-inline" for="2"><input name="news" id="2" type="checkbox"> Cash On Delivery</label>
                                    </div>
                                </div>
                            </div>
                            <div class="single-widget">
                                <div class="form-group">
                                    <h2>Collection Time<span>*</span></h2>
                                    {{ form.pickUpTime(size=32) }}
                                </div>
                            </div>

                            <div class="col-12">
                                <div class="form-group button">
                                    <button type="submit" class="btn ">{{ form.submit() }}</button>

                                </div>
                            </div>
                            </form>

This is what is in my main checkout function and the collection time variable is empty even though ive imported timeChoices from forms.py

if form.validate_on_submit():
    collectionTime = dict(timeChoices).get(form.pickUpTime.data)

Here is my forms.py

timeChoices = [(1, '7:00'), (2, '7:30'), (3, '8:00'), (4,'8:30'),(5,'9:00'), (6,'9:30')]

class CheckoutForm(FlaskForm):
    pickUpTime = SelectField(u'Pick Up Time', choices=timeChoices, validators=[DataRequired()])
    submit = SubmitField('Checkout')
question from:https://stackoverflow.com/questions/65901008/getting-selectfield-from-wtf-forms-flask

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...