Hello,

complementing template filters, sometimes it is necessary to format dates also in Python code, that is, achieve the equivalent to

    {{ value|date:"M" }}

For this, I'm using

    from django.utils import dateformat
    dateformat.format(value, "M")

(This works in Django views and in test cases, but not in `./manage.py shell`.)

As `dateformat.format()` is not covered in https://docs.djangoproject.com/en/2.1/ref/utils/, but still very useful e.g. in tests, my question is if this is the correct way to achieve in Python what the `date` template filter does? Are there alternatives? (`strftime()` does not provide translated months names etc., and so isn't).

Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb938e74-d2e3-e4cf-13fa-580befd8f49c%40cafu.de.
For more options, visit https://groups.google.com/d/optout.

Reply via email to