我有一個小Flask應用程序,它有三個字段(目標,開始時間和結束時間)。我想在選擇開始日期和結束日期時使用DatePicker小部件來顯示日曆。Flask&WTForms:DatePicker Widget顯示日期
使用我當前的腳本,日期小部件根本不會產生。我在這裏錯過了什麼?
app.py:
# -*- coding: utf-8 -*-
from flask.ext.wtf import Form
from wtforms import SubmitField, SelectField, DateField
from flask import Flask, render_template, request
from flask.ext.bootstrap import Bootstrap
from flask.ext.admin.form.widgets import DatePickerWidget
class GeneralForm(Form):
destination = SelectField(choices = data)
start_time = DateField('Start at', widget=DatePickerWidget())
end_time = DateField('End at', widget=DatePickerWidget())
submit = SubmitField('Submit')
@app.route("/", methods=['GET', 'POST'])
def index():
form = GeneralForm(request.form)
if request.method == 'POST':
destination = form.destination.data
start_time = form.start_time.data
end_time = form.end_time.data
return render_template('page.html', form=form)
else:
return render_template('index.html', form=form)
bootstrap = Bootstrap(app)
if __name__ == '__main__':
app.run(debug=True)
index.html:
<link rel="stylesheet"
href="{{url_for('.static', filename='mystyle.css')}}">
<link rel="stylesheet"
href="{{url_for('.static', filename='datepicker.css')}}">
<link rel="javascript"
href="{{url_for('.static', filename='main.js')}}">
<link rel="javascript"
href="{{url_for('.static', filename='bootstrap-datepicker.js')}}"
<form action="#" method="post">
{{ form.destination }}
{{ form.start_time(class='datepicker') }}
{{ form.end_time(class='datepicker') }}
{{ form.submit }}
</form>
是的,實際上我試過{{wtf.quick_form(form)}}。不過,我仍然無法使datepicker窗口小部件工作。感謝您的答覆! – jjjayn