niwinz / django-jinja

Simple and nonobstructive jinja2 integration with Django.
http://niwinz.github.io/django-jinja/latest/
BSD 3-Clause "New" or "Revised" License
363 stars 102 forks source link

Is it possible to use settings.DATETIME_FORMAT with django-jinja? #253

Closed max-block closed 2 years ago

max-block commented 4 years ago

Are there any solutions how to have a default datetime formatter with jinja?

wizpig64 commented 4 years ago

I have run into this too. Switching a template from django to jinja will always break date formatting.

Django's template engine implicitly renders {{ value }} as {{ value|date }}, if the value is a date or datetime. From what I can tell, jinja simply runs {{ str(value) }}, which is not as pretty as the django date filter.

django-jinja does the work of hooking up django's date filter, so switching your templates to {{ value|date }} should get it to render according like how django does it, and this is what I do in my project. Edit: I do also see {{ value|date('DATETIME_FORMAT') }} being used to explicitly refer to the settings format string in a few cases.

I do not know of a way to instruct jinja to use a default filter for a certain type, like django implicitly does for date types, if that is what you mean.

wizpig64 commented 2 years ago

marking this as closed as I've addressed the question. however, i would support a PR that emulates the django behavior.