0

I have wtforms defined for datetime field as below:

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')))

On HTML page calling this fields as below:

<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>

Flask Code:

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)

Problem is that, i get time in UTC and is not updating to current UTC value whenever i reload page.It stays same as i start run python code. Anything wrong in defining DateTimeField ?

Changed as below,still no luck:

  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)
1
  • etime = DateTimeField(label='End time(EDT)', validators=[validators.InputRequired()], format="%d%b%Y %H:%M", default=datetime.today) -> Did like this still it is same no change in time after reload
    – ajay
    Aug 31, 2017 at 15:36

1 Answer 1

0

Answer is in wtforms+flask today's date as a default value

Someone quoted this earlier. My bad i was editing at wrong place.

changed to :

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.