[Answered ]-Need helping with date format in Django

1๐Ÿ‘

โœ…

You can do it in the view (not in the template).

  • Create 2 variables (1 corresponding to now, 1 corresponding to now+1month)
  • Pass them to your template

In views.py

from datetime import datetime
def yourView(request):

    now_date = datetime.now()
    now_date_plus_1m = ... # I let you search how to to this :)

    return render_to_response('your_template.html',
        {
            'now_date': now_date,
            'now_date_plus_1m': now_date_plus_1m
        },
            RequestContext(request)
        )

In your template file:

.datetimepicker({value:'{{ now_date|date:"Y-m-d H:i" }}',step:10});
.datetimepicker({value:'{{ now_date_plus_1m|date:"Y-m-d H:i" }}',step:10});

๐Ÿ‘คDavid Dahan

1๐Ÿ‘

The django template system is meant to express presentation, not program logic this why you should do your logic at the view level

Leave a comment