'str' object has no attribute 'tzinfo'

5,379 views
Skip to first unread message

Inter Nemo

unread,
Jan 3, 2018, 12:49:18 PM1/3/18
to Django users
Django: 2.0.1
Error:
'str' object has no attribute 'tzinfo'
File:
...\AppData\Local\Programs\Python\Python36\lib\site-packages\pytz\__init__.py in localize
Code:

        if dt.tzinfo is not None:

Local vars:
Variable Value
dt
'0000-00-00 00:00:00.000000'
is_dst
None
self
<UTC>

Julio Biason

unread,
Jan 3, 2018, 12:53:25 PM1/3/18
to django...@googlegroups.com
It looks like you're trying to localize a string, which is not a datetime object and, thus, doesn't have a tzinfo property.

You'll have to convert your string to a datetime before trying to localize it.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/43042199-3f20-4fef-bf30-9a4c53c32d6e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

Inter Nemo

unread,
Jan 3, 2018, 1:28:26 PM1/3/18
to Django users
(sorry for my bad english)

i upgrade Django with 1.10 to 2.0 and and this error appeared.

if i change my db field:
UPDATE `articles` SET `edit_date`='2017-04-11 15:41:04.760678' where `edit_date`='0000-00-00 00:00:00.000000'

Then the error disappears.


среда, 3 января 2018 г., 19:53:25 UTC+2 пользователь Julio Biason написал:
It looks like you're trying to localize a string, which is not a datetime object and, thus, doesn't have a tzinfo property.

You'll have to convert your string to a datetime before trying to localize it.
On Wed, Jan 3, 2018 at 3:42 PM, Inter Nemo <pmrto...@gmail.com> wrote:
Django: 2.0.1
Error:
'str' object has no attribute 'tzinfo'
File:
...\AppData\Local\Programs\Python\Python36\lib\site-packages\pytz\__init__.py in localize
Code:

        if dt.tzinfo is not None:

Local vars:
Variable Value
dt
'0000-00-00 00:00:00.000000'
is_dst
None
self
<UTC>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Inter Nemo

unread,
Jan 3, 2018, 1:56:30 PM1/3/18
to Django users
Field in models.py

    edit_date = models.DateTimeField('Edit the date', auto_now=True)


Reply all
Reply to author
Forward
0 new messages