I'm making a project on Flask and I need to set the default value for the wtforms.DateTimeField()
def new_edit_task(task):
class EditTask(FlaskForm):
new_name = StringField('Name of task', validators=[DataRequired()], default=task.name)
new_description = TextAreaField('Description', validators=[DataRequired()], default=task.description)
new_deadline = DateTimeField("Deadline", format='%Y-%m-%dT%H:%M',
default=task.deadline)
new_link = StringField('Email', validators=[DataRequired()], default=task.link)
submit = SubmitField('Отправить')
return EditTask()
task is an SQLAlchemy model and task.deadline is datetime.datetime object.
That's how I render new_deadline field in HTML:
{{ form.new_deadline(class="half-width", type='datetime-local') }}<br>
{% for error in form.new_deadline.errors %}
<p class="alert alert-danger" role="alert">
{{ error }}
</p>
{% endfor %}
form is EditForm object here
But it doesn't work. There is "dd.mm.yyyy --:--" on the page.
Can you please explain to me what am I doing wrong?