我正在嘗試在 Flask WT Forms 中實作 DateTimeLocalField 但是該欄位不回傳資料。其他領域作業正常。
from flask_wtf import FlaskForm
from wtforms.fields import DateTimeLocalField
class AddLegForm(FlaskForm):
origin_datetime = DateTimeLocalField('Origin Time')
在views.py中:
@loads_blueprint.route('/add_leg/<load_id>', methods=['GET', 'POST'])
@login_required
def add_leg(load_id):
leg = db.session.query(Legs)
form = AddLegForm()
print(type(form.origin_datetime.data))
print(form.origin_datetime.data)
列印陳述句顯示:
<class 'NoneType'>
None
我的表格中也有StringField',所有其他資料都在那里。
最小的 HTML:
<form method="POST", action="/loads/add_leg/{{load_id}}">
{{ form.hidden_tag() }}
<div class="form-outline mb-4">
{{ form.origin_datetime.label }}
{{ form.origin_datetime(class_="form-control", size=32) }}
</div>
<button type="submit" class="btn btn-primary float-end">Submit</button>
</form>
uj5u.com熱心網友回復:
這可能是格式問題,如果您使用:
origin_datetime = DateTimeLocalField('Origin Time', format='%Y-%m-%dT%H:%M')
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/522841.html
標籤:烧瓶烧瓶-wtforms
上一篇:資料框中的字典值
