簡體   English   中英

在 python 中使用 wtforms 循環時間

[英]round time using wtforms in python

我在 python 中使用 wtforms,一切正常,但我想將 TimeFiled 舍入到小時,並將分鍾保持在 00。例如 14:00、15:00,所以用戶只能選擇小時,而不是分鍾。


我的 forms.py:

    class DateForm(FlaskForm):
        name = StringField("Nombre", validators=[DataRequired()])
        email = StringField("Email", validators=[DataRequired()])
        date = DateField("Fecha", validators=([InputRequired(), DataRequired()]))
        hour = TimeField("Hora", validators=([InputRequired(), DataRequired()]))
        submit = SubmitField("Agendar cita")

我的約會。html:

     {{ form.csrf_token() }}
     {{ wtf.quick_form(form, novalidate=True, button_map={"submit": "primary"}) }}
      {% with messages = get_flashed_messages() %}
      {% if messages %}
        {% for message in messages %}
         <p style="color:red">{{ message }}</p>
        {% endfor %}
      {% endif %}
    {% endwith %}

這是它現在的樣子: 在此處輸入圖像描述 我怎樣才能做到這一點? 提前致謝!

目前我可以通過在 function 中添加驗證來找到解決方法:

elif form.hour.data.minute:= 0. “提出消息”。

但我認為每小時只向用戶顯示 00 分鍾會更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM