Django Want to print date and time for today

I want to print some kind of timestamp or some function to determine what day and how much time it is in the template. In my mind I have

time = datetime.now()

and in my template I

{{time}}

All this means that the object returns <type 'datetime.date'>.

+5
source share
2 answers

Usually this should work:

from datetime import datetime

def a_view(request):
    return render_to_response("a_template.html", {
        'time':datetime.now(),
        }, context_instance=RequestContext(request))

Then render the datetime object in your template:

<p>{{time}}</p>

Use the built-in date filter as described here to format the date if you wish.

+2
source

if its only in template use now

It is {% now "f" %}
+60

All Articles