Answer the question
In order to leave comments, you need to log in
How to subtract another (DateTimeField) from the current date in template?
The user filled out the form and specified some date through the DateTimeField field, everything was saved to the database.
On another page, I want to display all users and for each, instead of the selected date, show "Current_date - user_selected_date" in years.
Google issues solutions via import datetime, but all this is in views.py, and I need to do this in a template (templates.py). In a template it is impossible to do import datetime? Please tell me how can I do this?
Answer the question
In order to leave comments, you need to log in
It is not necessary to carry out calculations in the template, this violates MVC / MVT. Either do the necessary calculations in the view and pass it to the template context, or write a template tag that performs such calculations, and it would be quite good to create a calculated property of the model.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question