1

I have a template tag that returns a date from a model field. If the date is today, I want to render some other content. Using the now builtin-templatetag: https://docs.djangoproject.com/en/1.11/ref/templates/builtins/#now, I used logic similar to the answer in this previously posted answer:

https://stackoverflow.com/a/34959070/5616606

{% now "Y-m-d" as todays %}
{% if self.date|date:"Y-m-d" == todays %}
   ...add some content
{% endif %}

I am trying to do this without creating a custom filter, context processor or edit the view. The problem, I believe, is with the timezone. This works until later in the evening when now returns the next day, instead of the current day. I researched Django's date and timezone documentation but am not sure how make the timezone returned from now match the timezone of the model field without having to create a context processor or edit the view.

Astik Anand
  • 12,757
  • 9
  • 41
  • 51
JohnnyP
  • 426
  • 1
  • 7
  • 12
  • Just to complement this question and its answer: if you want to use dates in a template (get type `date` or `datetime` instead of type `str` that is returned by the built-in `now`), I listed a few options to achieve that in [this answer](https://stackoverflow.com/a/52336898/9225671). – Ralf Jun 02 '19 at 20:14

0 Answers0