115๐
โ
You probably have
import datetime
change that to
from datetime import datetime
Demo:
>>> import datetime
>>> datetime.now()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'now'
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2013, 10, 7, 13, 57, 18, 456504)
>>>
Also, you will run into issues due to indentation. Please fix those.
๐คkarthikr
12๐
When you do
import datetime
you have to use
>>> datetime.datetime.now()
datetime.datetime(2016, 12, 14, 1, 15, 58, 606802)
otherwise if you import like
>>> from datetime import datetime
>>> datetime.now()
datetime.datetime(2016, 12, 14, 1, 17, 31, 772406)
But on some machine you could refer to wrong datetime module because of sys.path , instead of doing from datetime import datetime
or import datetime
make a habbit of using
from datetime import datetime as dt
๐คRizwan Mumtaz
- [Django]-Error trying to install Postgres for python (psycopg2)
- [Django]-Passing variable urlname to url tag in django template
- [Django]-Django โ Clean permission table
2๐
i had the same problem when i used
from datetime import datetime,date,timedelta
import pytz
utc=pytz.UTC
today = datetime.now().replace(tzinfo=utc)
Solution for this which i will suggest is to import all the dependencies
from datetime import *
import pytz
utc=pytz.UTC
today = datetime.now().replace(tzinfo=utc)
๐คYash Rastogi
- [Django]-Using subdomains in django
- [Django]-Django REST Framework serializer field required=false
- [Django]-Django 1.8: Create initial migrations for existing schema
Source:stackexchange.com