I’m trying to do this, and failing. Is there any reason why it wouldn’t work in Django template syntax? I’m using the latest version of Django.
{% ifequal entry.created_at|timesince '0 minutes' %}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It doesn’t work because it’s not supposed to work. What you’re asking for is not part of the template language.
You can’t apply a filter in the middle of tag like
{% ifequal. When a template tag uses a variable, it doesn’t expect an expression, it expects a variable, nothing more.That kind of logic — extracting time since, comparing, etc. — is what you’re supposed to do in your view function.
Your view function then puts a ‘zerominutes’ item in the context for the template to use. Templates just can’t do much processing.
They’re designed to do the minimum required to render HTML. Everything else needs to be in your view function.