0

I have some flask code which renders a html document like this

html = render_template('test.html', data=data)

where test.html is given by

<div>
    {{ moment(data.date).fromNow() }}
</div>

I am using the moment.js file to print the time difference between now and the date. However, in the example above the moment function does not work. I tried to include the moment function into the template like

{% block scripts %}
    {{ moment.include_moment() }}
{% endblock %} 

but this does not seem to do the trick... how can I get a javascript function to work in this context?

3
  • It looks like you are trying to mix JavaScript and Python Commented Jun 6, 2016 at 14:07
  • yes I am trying to render a template and feed the html code with javascript/ajax into the current view of the user Commented Jun 6, 2016 at 14:10
  • Can you post the full file please? Commented Jun 6, 2016 at 14:33

1 Answer 1

1

If you want to achive time since date and the date is anyway taken from python so why don't you use timesince filter. Here you will find about adding custom fitlers. It would be more transparent solution i think.

Then it could look like this:

<div>
    {{ data.date|timesince }}
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.