K
K
Konstantin Malyarov2020-01-12 19:36:32
Django
Konstantin Malyarov, 2020-01-12 19:36:32

How to change content output from db in templarte?

There is a request from a DB where 5 objects come:
I display in the for loop.
But time comes in UNIX format (ex. 15561253451), I want to get str format.

{% extends 'user/template.html' %}

{% block content %}
    {% for signal in signals %}
        {{ signal.close_time }}
    {% endfor %}
{% endblock %}

Something like this:
{% extends 'user/template.html' %}

{% block content %}
    {% for signal in signals %}
        {{ datetime.utcfromtimestamp(signal["close_time"]).strftime('%Y-%m-%d %H:%M:%S') }}
    {% endfor %}
{% endblock %}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question