Django Want to print the date & time for today
I want to print some sort of time stamp or some sort of function to tell what day and time it is in a template. In my views I have
time = datetime.now()
and in my template I have
{{time}}
All this does is prin开发者_运维知识库ts out a <type 'datetime.date'>
object.
if its just in the template, use now
It is {% now "f" %}
Normally, 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 your date if you like.
精彩评论