How do I compare dates in a Django template? I thought of several possible avenues:
- Send today’s date in the context to be compared at the template
- Create my own template tag
- Have some logic in the view to only pass the date if it’s in the future
Although the last option seems easier, I rather leave the display logic in the template than in the view. I also do not want to pass something that seems so trivial like today’s date in the template context.
Perhaps someone has another option or could share their implementation of one of the options I mentioned above and why they decided to go that route.
I’d go with a template filter:
Then in your view do something like: