我有一个小的Flask应用程序,其中包含三个字段(目的地、开始时间和结束时间)。我想使用DatePicker小部件在选择开始和结束日期时显示日历。
使用当前的脚本,日期小部件根本没有出现。我在这里缺少什么?
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>