git-e
git-e

Reputation: 299

moment.js date in Django template

I want to display the date of the relevant text (for example, 3 days ago) using the moment.js. But my code does not work.

My code, but it does not work:

<div class="base">
    <script type="text/javascript">
        var time = {{ obj.pub_date|date:'Ymd' }};
        moment(time, "YYYYMMDD").fromNow();
    </script>
    <p>{{ obj.text }}</p>
</div>

Upvotes: 0

Views: 2839

Answers (1)

jonnyhocks
jonnyhocks

Reputation: 131

You are not assigning whatever is returned from your .fromNow() call to a variable, or doing anything with it.

Upvotes: 3

Related Questions