WTForms 日期时间字段时间未更新
WTForms datetime field time is not updating
我为日期时间字段定义了 wtforms,如下所示:
stime = DateTimeField(label='Start time',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.now(timezone('UTC')))
etime = DateTimeField(label='End time',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.now(timezone('UTC')))
在 HTML 页面调用此字段如下:
<form method= POST action="{{ url_for('input_ext') }}">
<table>
{% for field in form %}
<tr>
<td>{{ field.label }}*</td><td>{{ field }}</td>
</tr>
{% endfor %}
</table>
<input id = "generate" name="generate" type=submit value=Next></form>
烧瓶代码:
from flask import Flask
from flask import render_template
from flask import request
from model import InputForm
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
#select interface and for selected interfaces pullup circuit info
def provideinput():
global devices
devices = ''
form = InputForm(request.form)
return render_template("utctime.html", form=form)
if __name__ == "__main__":
app.run(debug=True,host="10.23.102.116",port=82)
问题是,我在 UTC 中获取时间,并且每当我重新加载时都不会更新到当前的 UTC 值 page.It 与我开始 运行 python 代码时保持相同。
定义 DateTimeField 有什么问题吗?
修改如下,还是不行:
stime = DateTimeField(label='Start time(EDT)', validators=[validators.InputRequired()], format="%d%b%Y %H:%M",
default=datetime.today)
etime = DateTimeField(label='End time(EDT)', validators=[validators.InputRequired()], format="%d%b%Y %H:%M",
default=datetime.today)
答案在wtforms+flask today's date as a default value
之前有人引用过这个。糟糕,我在错误的地方编辑。
更改为:
stime = DateTimeField(label='Start time(EDT)',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.utcnow)
etime = DateTimeField(label='End time(EDT)',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.utcnow)
我为日期时间字段定义了 wtforms,如下所示:
stime = DateTimeField(label='Start time',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.now(timezone('UTC')))
etime = DateTimeField(label='End time',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.now(timezone('UTC')))
在 HTML 页面调用此字段如下:
<form method= POST action="{{ url_for('input_ext') }}">
<table>
{% for field in form %}
<tr>
<td>{{ field.label }}*</td><td>{{ field }}</td>
</tr>
{% endfor %}
</table>
<input id = "generate" name="generate" type=submit value=Next></form>
烧瓶代码:
from flask import Flask
from flask import render_template
from flask import request
from model import InputForm
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
#select interface and for selected interfaces pullup circuit info
def provideinput():
global devices
devices = ''
form = InputForm(request.form)
return render_template("utctime.html", form=form)
if __name__ == "__main__":
app.run(debug=True,host="10.23.102.116",port=82)
问题是,我在 UTC 中获取时间,并且每当我重新加载时都不会更新到当前的 UTC 值 page.It 与我开始 运行 python 代码时保持相同。 定义 DateTimeField 有什么问题吗?
修改如下,还是不行:
stime = DateTimeField(label='Start time(EDT)', validators=[validators.InputRequired()], format="%d%b%Y %H:%M",
default=datetime.today)
etime = DateTimeField(label='End time(EDT)', validators=[validators.InputRequired()], format="%d%b%Y %H:%M",
default=datetime.today)
答案在wtforms+flask today's date as a default value
之前有人引用过这个。糟糕,我在错误的地方编辑。
更改为:
stime = DateTimeField(label='Start time(EDT)',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.utcnow)
etime = DateTimeField(label='End time(EDT)',validators=[validators.InputRequired()],format = "%d%b%Y %H:%M",default= datetime.utcnow)