How can I format a date in html from flask render_template? I am getting cabinet table from sqlalchemy where the date is formatted 2020-03-31 10:55:15.500207
. I just need %Y-%m-%d
.
{% for item in cabinet %}
<tr>
<td>{{item.name}}</td>
<td>{{item.stocktaking.strftime('%Y-%m-%d')}}</td>
<td>
{% if item.incomplete == true %}<span class="btn btn-sm btn-secondary">Incomplete</span>
{% else %}<span class="btn btn-sm btn-success">Complete</span>
{% endif %}
</td>
<td><a class="btn btn-sm btn-primary" href="{{ url_for('stocktaking_cabinet', name=item.name) }}" role="button">Show</a></td>
<td><a class="btn btn-sm btn-danger" href="{{ url_for('stocktaking_cabinet_reset', name=item.name) }}" role="button">Reset</a></td>
</tr>
Table:
class Cabinet(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(20))
stocktaking = db.Column(db.DateTime, default=datetime.now())
incomplete = db.Column(db.Boolean)
strftime('%Y-%m-%d')
is not working inside the html. It shows this error :
jinja2.exceptions.UndefinedError: 'None' has no attribute 'strftime'