[Python] Convert Unix timestamp returned from API in Python Flask app

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have got a Python Flask app that will get data from API and pass it to html template.

    On html template I have following and I would like to convert the "insertionTime" from Unix timestamp to human readable format.

    <div class="results">

    {% if results %}
    <h2>Results:</h2>
    <ul>
    {% for result in results %}
    <li><strong>{{ result['id'] }}</strong><br>{{ result['insertionTime'] }}<br>{{ result['eventType'] }}<br>{{ result['activity'] }}</li>
    <hr>
    {% endfor %}
    </ul>
    {% else %}
    <p>No results found.</p>
    {% endif %}
    </div>


    I have added flask_moment and changed to the following but it throws AttributeError: 'int' object has no attribute '_render'

    <br>{{ moment.unix(result['insertionTime']).format(LLL) }}<br>


    Any help would be much appreciated, thank you.

    Continue reading...

Compartilhe esta Página