Python: datetime.today().date() crashes in Django but runs in terminal -
i have following code in django app keeps crashing:
from datetime import * date_today = datetime.today().date()
if run exact same code in terminal, works , prints datetime.date(2016, 11, 10)
the error when code run django:
attributeerror: 'module' object has no attribute 'today'
question: can make code run in django?
i guarantee not running exact code in django. certainly, did import datetime
rather from datetime import *
.
confusingly, datetime module contains class called datetime
; class imported from ...
syntax, , has today
method.
doing import datetime
imports module, not have method; instead need datetime.datetime.today()
.
Comments
Post a Comment