233👍
This is exactly what you want. Try this:
{{ wpis.entry.lastChangeDate|date:'Y-m-d H:i' }}
- [Django]-AWS: can't connect to RDS database from my machine
- [Django]-Django test runner not finding tests
- [Django]-Django return redirect() with parameters
5👍
I suspect wpis.entry.lastChangeDate
has been somehow transformed into a string in the view, before arriving to the template.
In order to verify this hypothesis, you may just check in the view if it has some property/method that only strings have – like for instance wpis.entry.lastChangeDate.upper
, and then see if the template crashes.
You could also create your own custom filter, and use it for debugging purposes, letting it inspect the object, and writing the results of the inspection on the page, or simply on the console. It would be able to inspect the object, and check if it is really a DateTimeField.
On an unrelated notice, why don’t you use models.DateTimeField(
auto_now_add
=True)
to set the datetime on creation?
- [Django]-Mac OS X – EnvironmentError: mysql_config not found
- [Django]-Django's Double Underscore
- [Django]-Python + Django page redirect
3👍
{{ wpis.entry.lastChangeDate|date:"SHORT_DATETIME_FORMAT" }}
Replace SHORT_DATETIME_FORMAT with the date and/or time format you desire to use.
Here’s a list of available date and time formats to use in Django templates :
https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#date
https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#time
Make sure the filter is applied to the correct field.
- [Django]-How to get a favicon to show up in my django app?
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Pycharm error Django is not importable in this environment
2👍
In addition to other answers, time filter below can only show a formatted time:
{{ wpis.entry.lastChangeDate|time:'H:i' }}
- [Django]-Whats the difference between using {{STATIC_URL}} and {% static %}
- [Django]-Django: show the count of related objects in admin list_display
- [Django]-How to access the user profile in a Django template?