Flask - Flask-Moment gives out an error: AttributeError: 'str' object has no attribute 'strftime' Flask - Flask-Moment gives out an error: AttributeError: 'str' object has no attribute 'strftime' flask flask

Flask - Flask-Moment gives out an error: AttributeError: 'str' object has no attribute 'strftime'


EDIT:

You can also try using:

{{ row.created_at.strftime('%M %d, %Y') }}

or the jinja datetime filter:

{{ row.created_at|datetime }}

ORIGINAL ANSWER:

It appears you need to convert from MySQL DateTime to Python datetime. Without seeing more of your code, maybe something like this would work, though there is probably a more efficient way:

# get resultsusers = cur.fetchall()for user in users:    user.created_at = datetime.strptime(user.created_at, '%Y-%M-%d') # you have to use the mysql format herereturn render_template('users.html', title = 'User Accounts', users=users)

You are using strftime when it appears that python is interpreting the MySQL datetime as a string, not a datetime() object, so you have to use strptime